Skip to content

Commit 74e70d3

Browse files
authored
fix(generator): introspection respect options (#1257)
1 parent f33498a commit 74e70d3

File tree

4 files changed

+139
-2
lines changed

4 files changed

+139
-2
lines changed

src/generator/config/__snapshots__/config.test.ts.snap

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,115 @@ exports[`can load schema from custom path 1`] = `
145145
}
146146
"
147147
`;
148+
149+
exports[`configured schema introspection options are passed to introspection 1`] = `
150+
{
151+
"query": "
152+
query IntrospectionQuery {
153+
__schema {
154+
155+
queryType { name }
156+
mutationType { name }
157+
subscriptionType { name }
158+
types {
159+
...FullType
160+
}
161+
directives {
162+
name
163+
164+
165+
locations
166+
args {
167+
...InputValue
168+
}
169+
}
170+
}
171+
}
172+
173+
fragment FullType on __Type {
174+
kind
175+
name
176+
177+
178+
179+
fields(includeDeprecated: true) {
180+
name
181+
182+
args {
183+
...InputValue
184+
}
185+
type {
186+
...TypeRef
187+
}
188+
isDeprecated
189+
deprecationReason
190+
}
191+
inputFields {
192+
...InputValue
193+
}
194+
interfaces {
195+
...TypeRef
196+
}
197+
enumValues(includeDeprecated: true) {
198+
name
199+
200+
isDeprecated
201+
deprecationReason
202+
}
203+
possibleTypes {
204+
...TypeRef
205+
}
206+
}
207+
208+
fragment InputValue on __InputValue {
209+
name
210+
211+
type { ...TypeRef }
212+
defaultValue
213+
214+
215+
}
216+
217+
fragment TypeRef on __Type {
218+
kind
219+
name
220+
ofType {
221+
kind
222+
name
223+
ofType {
224+
kind
225+
name
226+
ofType {
227+
kind
228+
name
229+
ofType {
230+
kind
231+
name
232+
ofType {
233+
kind
234+
name
235+
ofType {
236+
kind
237+
name
238+
ofType {
239+
kind
240+
name
241+
ofType {
242+
kind
243+
name
244+
ofType {
245+
kind
246+
name
247+
}
248+
}
249+
}
250+
}
251+
}
252+
}
253+
}
254+
}
255+
}
256+
}
257+
",
258+
}
259+
`;

src/generator/config/config.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,28 @@ test(`can introspect schema from url`, async ({ pokemonService }) => {
2525
expect(config.paths.project.inputs.schema).toEqual(null)
2626
expect(config.schema.sdl).toMatchSnapshot()
2727
})
28+
29+
test(`configured schema introspection options are passed to introspection`, async ({ pokemonService, fetch }) => {
30+
fetch.mockImplementation(_ => {
31+
const response = new Response(JSON.stringify({ data: null }))
32+
return Promise.resolve(response)
33+
})
34+
await createConfig({
35+
schema: {
36+
type: `url`,
37+
url: pokemonService.url,
38+
options: {
39+
descriptions: false,
40+
directiveIsRepeatable: false,
41+
inputValueDeprecation: false,
42+
schemaDescription: false,
43+
oneOf: false,
44+
specifiedByUrl: false,
45+
},
46+
},
47+
}).catch((_: unknown) => {})
48+
const readableStream: ReadableStream = fetch.mock.calls[0]?.[0]?.body as any
49+
const { value }: { value: Uint8Array } = await readableStream.getReader().read() as any
50+
const document = JSON.parse(new TextDecoder().decode(value))
51+
expect(document).toMatchSnapshot()
52+
})

src/generator/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ const createConfigSchema = async (
282282
}
283283
}
284284
case `url`: {
285-
const graffle = Graffle.create({ schema: input.schema.url }).use(Introspection())
285+
const graffle = Graffle.create({ schema: input.schema.url }).use(Introspection({ options: input.schema.options }))
286286
const data = await graffle.introspect()
287287
if (!data) {
288288
throw new Error(`No data returned for introspection query.`)

src/requestPipeline/RequestPipeline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const RequestPipeline = Anyware.Pipeline.create<HookSequence, HookMap, Gr
8686
const methodMode = input.state.config.transport.config.methodMode
8787
const requestMethod = methodMode === MethodMode.post
8888
? `post`
89-
: methodMode === MethodMode.getReads
89+
: methodMode === MethodMode.getReads // eslint-disable-line
9090
? OperationTypeToAccessKind[operationType] === `read` ? `get` : `post`
9191
: casesExhausted(methodMode)
9292

0 commit comments

Comments
 (0)