Skip to content

Commit 8240c2c

Browse files
committed
Add test to confirm schema astNode property is populated
1 parent ca705fb commit 8240c2c

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

packages/apollo-graphql/src/schema/__tests__/buildSchemaFromSDL.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,29 @@ type MutationRoot {
351351
`"Unknown directive \\"@something\\"."`
352352
);
353353
});
354+
355+
it(`should preserve directive usages from the schema definition node`, () => {
356+
const schema = buildSchemaFromSDL(
357+
gql`
358+
directive @contact(
359+
name: String!
360+
url: String!
361+
description: String
362+
) on SCHEMA
363+
364+
schema
365+
@contact(
366+
name: "Contact"
367+
url: "http://example.com/contact"
368+
description: "Testing"
369+
) {
370+
query: Query
371+
}
372+
`
373+
);
374+
expect(schema.astNode?.directives).toHaveLength(1);
375+
expect(schema.astNode?.directives![0].name.value).toEqual("contact");
376+
});
354377
});
355378

356379
describe(`resolvers`, () => {

packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function buildSchemaFromSDL(
132132
directiveDefinitions.push(definition);
133133
} else if (definition.kind === Kind.SCHEMA_DEFINITION) {
134134
schemaDefinitions.push(definition);
135-
schemaDirectives.push(...(definition.directives ?? []))
135+
schemaDirectives.push(...(definition.directives ?? []));
136136
} else if (definition.kind === Kind.SCHEMA_EXTENSION) {
137137
schemaExtensions.push(definition);
138138
}

0 commit comments

Comments
 (0)