-
Notifications
You must be signed in to change notification settings - Fork 242
/
printSubgraphSchema.test.ts
175 lines (142 loc) 路 4.54 KB
/
printSubgraphSchema.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { fixtures } from 'apollo-federation-integration-testsuite';
import { buildSubgraphSchema } from '../buildSubgraphSchema';
import { printSubgraphSchema } from '../printSubgraphSchema';
describe('printSubgraphSchema', () => {
it('prints a subgraph correctly', () => {
const schema = buildSubgraphSchema(fixtures[0].typeDefs);
expect(printSubgraphSchema(schema)).toMatchInlineSnapshot(`
"schema {
query: RootQuery
mutation: Mutation
}
directive @stream on FIELD
directive @transform(from: String!) on FIELD
directive @cacheControl(maxAge: Int, scope: CacheControlScope, inheritMaxAge: Boolean) on FIELD_DEFINITION | OBJECT | INTERFACE | UNION
enum CacheControlScope {
PUBLIC
PRIVATE
}
scalar JSON @specifiedBy(url: \\"https://json-spec.dev\\")
type PasswordAccount @key(fields: \\"email\\") {
email: String!
}
type SMSAccount @key(fields: \\"number\\") {
number: String
}
union AccountType = PasswordAccount | SMSAccount
type UserMetadata {
name: String
address: String
description: String
}
type User @key(fields: \\"id\\") @key(fields: \\"username name { first last }\\") {
id: ID!
name: Name
username: String
birthDate(locale: String): String
account: AccountType
metadata: [UserMetadata]
ssn: String
}
type Name {
first: String
last: String
}
type Mutation {
login(username: String!, password: String!, userId: String @deprecated(reason: \\"Use username instead\\")): User
}
extend type RootQuery {
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
user(id: ID!): User
me: User
}
extend type Library @key(fields: \\"id\\") {
id: ID! @external
name: String @external
userAccount(id: ID! = 1): User @requires(fields: \\"name\\")
}
"
`);
});
it('prints reviews subgraph correctly', () => {
const schema = buildSubgraphSchema(fixtures[5].typeDefs);
expect(printSubgraphSchema(schema)).toMatchInlineSnapshot(`
"directive @stream on FIELD
directive @transform(from: String!) on FIELD
type Review @key(fields: \\"id\\") {
id: ID!
body(format: Boolean = false): String
author: User @provides(fields: \\"username\\")
product: Product
metadata: [MetadataOrError]
}
input UpdateReviewInput {
id: ID!
body: String
}
input ReviewProduct {
upc: String!
body: String!
stars: Int @deprecated(reason: \\"Stars are no longer in use\\")
}
type KeyValue {
key: String!
value: String!
}
type Error {
code: Int
message: String
}
union MetadataOrError = KeyValue | Error
extend type Query {
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
topReviews(first: Int = 5): [Review]
}
extend type UserMetadata {
address: String @external
}
extend type User @key(fields: \\"id\\") {
id: ID! @external
username: String @external
reviews: [Review]
numberOfReviews: Int!
metadata: [UserMetadata] @external
goodAddress: Boolean @requires(fields: \\"metadata { address }\\")
}
extend interface Product {
reviews: [Review]
}
extend type Furniture implements Product @key(fields: \\"upc\\") {
upc: String! @external
reviews: [Review]
}
extend type Book implements Product @key(fields: \\"isbn\\") {
isbn: String! @external
reviews: [Review]
similarBooks: [Book]! @external
relatedReviews: [Review!]! @requires(fields: \\"similarBooks { isbn }\\")
}
extend interface Vehicle {
retailPrice: String
}
extend type Car implements Vehicle @key(fields: \\"id\\") {
id: String! @external
price: String @external
retailPrice: String @requires(fields: \\"price\\")
}
extend type Van implements Vehicle @key(fields: \\"id\\") {
id: String! @external
price: String @external
retailPrice: String @requires(fields: \\"price\\")
}
extend type Mutation {
reviewProduct(input: ReviewProduct!): Product
updateReview(review: UpdateReviewInput!): Review
deleteReview(id: ID!): Boolean
}
"
`);
});
});