Skip to content

Commit

Permalink
fix(subgraph): Conditionally print @SpecifiedBy directive on scalars …
Browse files Browse the repository at this point in the history
…correctly (backport #1463) (`version-0.x`) (#1465)

Co-authored-by: Angelo Moreira <angelo.moreira@gmail.com>
  • Loading branch information
trevor-scheer and angelo-moreira authored Feb 1, 2022
1 parent 46c0395 commit 149f8b8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions subgraph-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.
- Print description text for the `schema` definition node, as allowed per the October 2021 edition of the GraphQL specification [PR #1442](https://github.com/apollographql/federation/pull/1442).
- Make sure scalars don't print a `specifiedBy` directive unless specified in the subgraph. [PR #1465](https://github.com/apollographql/federation/pull/1465)

## v0.1.5

Expand Down
15 changes: 15 additions & 0 deletions subgraph-js/src/__tests__/printSubgraphSchema.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fixtures } from 'apollo-federation-integration-testsuite';
import { buildSubgraphSchema } from '../buildSubgraphSchema';
import { printSubgraphSchema } from '../printSubgraphSchema';
import gql from 'graphql-tag';

describe('printSubgraphSchema', () => {
it('prints a subgraph correctly', () => {
Expand Down Expand Up @@ -77,6 +78,20 @@ describe('printSubgraphSchema', () => {
`);
});

it('prints a scalar without a directive correctly', () => {
const schema = gql`scalar JSON`;
const subgraphSchema = buildSubgraphSchema(schema);

expect(printSubgraphSchema(subgraphSchema)).toMatchInlineSnapshot(`
"scalar JSON
type Query {
_service: _Service!
}
"
`);
});

it('prints reviews subgraph correctly', () => {
const schema = buildSubgraphSchema(fixtures[5].typeDefs);
expect(printSubgraphSchema(schema)).toMatchInlineSnapshot(`
Expand Down
2 changes: 1 addition & 1 deletion subgraph-js/src/printSubgraphSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ function printSpecifiedByURL(scalar: GraphQLScalarType): string {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const value = (scalar as any).specifiedByUrl ?? scalar.specifiedByURL;

if (value === null) {
if (value == null) {
return '';
}
const astValue = print({
Expand Down

0 comments on commit 149f8b8

Please sign in to comment.