Skip to content

Commit

Permalink
Prevent parsing schema exceptions when importing directives (#900)
Browse files Browse the repository at this point in the history
* Prevent parsing schema extensions

* Add unit test
  • Loading branch information
Igloczek authored Nov 2, 2022
1 parent b4d70fc commit e27e5b0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/federation.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function getStubTypes (schemaDefinitions, isGateway) {
const directiveDefinitions = []

for (const definition of schemaDefinitions) {
if (definition.kind === 'SchemaDefinition') {
if (definition.kind === 'SchemaDefinition' || definition.kind === 'SchemaExtension') {
continue
}

Expand Down
42 changes: 42 additions & 0 deletions test/federation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1087,3 +1087,45 @@ test('basic federation support with \'schema\' in the schema', async (t) => {
}
})
})

test('should support directives import syntax', async (t) => {
const app = Fastify()

const schema = `
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key", "@shareable", "@override"])
extend type Query {
hello: String
}
`

const resolvers = {
Query: {
hello: () => 'world'
}
}

app.register(GQL, {
schema,
resolvers,
federationMetadata: true
})

await app.ready()

const query = '{ _service { sdl } }'
const res = await app.inject({
method: 'GET',
url: `/graphql?query=${query}`
})

t.same(JSON.parse(res.body), {
data: {
_service: {
sdl: schema
}
}
})
})

0 comments on commit e27e5b0

Please sign in to comment.