Skip to content

Commit

Permalink
fix(generator): introspection respect options (#1257)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Nov 11, 2024
1 parent f33498a commit 74e70d3
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 2 deletions.
112 changes: 112 additions & 0 deletions src/generator/config/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,115 @@ exports[`can load schema from custom path 1`] = `
}
"
`;
exports[`configured schema introspection options are passed to introspection 1`] = `
{
"query": "
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
fields(includeDeprecated: true) {
name
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
type { ...TypeRef }
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
}
}
",
}
`;
25 changes: 25 additions & 0 deletions src/generator/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,28 @@ test(`can introspect schema from url`, async ({ pokemonService }) => {
expect(config.paths.project.inputs.schema).toEqual(null)
expect(config.schema.sdl).toMatchSnapshot()
})

test(`configured schema introspection options are passed to introspection`, async ({ pokemonService, fetch }) => {
fetch.mockImplementation(_ => {
const response = new Response(JSON.stringify({ data: null }))
return Promise.resolve(response)
})
await createConfig({
schema: {
type: `url`,
url: pokemonService.url,
options: {
descriptions: false,
directiveIsRepeatable: false,
inputValueDeprecation: false,
schemaDescription: false,
oneOf: false,
specifiedByUrl: false,
},
},
}).catch((_: unknown) => {})
const readableStream: ReadableStream = fetch.mock.calls[0]?.[0]?.body as any
const { value }: { value: Uint8Array } = await readableStream.getReader().read() as any
const document = JSON.parse(new TextDecoder().decode(value))
expect(document).toMatchSnapshot()
})
2 changes: 1 addition & 1 deletion src/generator/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ const createConfigSchema = async (
}
}
case `url`: {
const graffle = Graffle.create({ schema: input.schema.url }).use(Introspection())
const graffle = Graffle.create({ schema: input.schema.url }).use(Introspection({ options: input.schema.options }))
const data = await graffle.introspect()
if (!data) {
throw new Error(`No data returned for introspection query.`)
Expand Down
2 changes: 1 addition & 1 deletion src/requestPipeline/RequestPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const RequestPipeline = Anyware.Pipeline.create<HookSequence, HookMap, Gr
const methodMode = input.state.config.transport.config.methodMode
const requestMethod = methodMode === MethodMode.post
? `post`
: methodMode === MethodMode.getReads
: methodMode === MethodMode.getReads // eslint-disable-line
? OperationTypeToAccessKind[operationType] === `read` ? `get` : `post`
: casesExhausted(methodMode)

Expand Down

0 comments on commit 74e70d3

Please sign in to comment.