From e27e5b01ae0210cdbc0de259175b1c011d258c80 Mon Sep 17 00:00:00 2001 From: Bartek Igielski Date: Wed, 2 Nov 2022 15:46:07 +0100 Subject: [PATCH] Prevent parsing schema exceptions when importing directives (#900) * Prevent parsing schema extensions * Add unit test --- lib/federation.js | 2 +- test/federation.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/federation.js b/lib/federation.js index 6c1258e4..11d6131f 100644 --- a/lib/federation.js +++ b/lib/federation.js @@ -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 } diff --git a/test/federation.js b/test/federation.js index 2c551039..4c1bcfa4 100644 --- a/test/federation.js +++ b/test/federation.js @@ -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 + } + } + }) +})