-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…#7274) Related to apollographql/apollo-federation-subgraph-compatibility#302 We found a discrepancy in how libraries implement the federation specification (`_Service.sdl` is `String` in Federation 1 and is `String` in Federation 2). I'm doing this PR mostly to check how easy it would be to support both specs at once, if I understood correctly the code `schemaIsSubgraph` might also be used outside Apollo Server 😊
- Loading branch information
Showing
3 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@apollo/server': patch | ||
--- | ||
|
||
Update schemaIsSubgraph to also support non nullable \_Service.sdl |
122 changes: 122 additions & 0 deletions
122
packages/server/src/__tests__/plugin/schemaIsSubgraph.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { schemaIsSubgraph } from '../../plugin/schemaIsSubgraph'; | ||
import { describe, it, expect } from '@jest/globals'; | ||
|
||
import { | ||
GraphQLSchema, | ||
GraphQLObjectType, | ||
GraphQLString, | ||
GraphQLInt, | ||
GraphQLNonNull, | ||
} from 'graphql'; | ||
|
||
describe('schemaIsSubgraph', () => { | ||
it('returns false when there is no service field', async () => { | ||
const schema = new GraphQLSchema({ | ||
query: new GraphQLObjectType({ | ||
name: 'QueryType', | ||
fields: { | ||
hello: { | ||
type: GraphQLString, | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
expect(schemaIsSubgraph(schema)).toBe(false); | ||
}); | ||
|
||
it('returns false when the sdl field is a not string', async () => { | ||
const schema = new GraphQLSchema({ | ||
query: new GraphQLObjectType({ | ||
name: 'QueryType', | ||
fields: { | ||
_service: { | ||
type: new GraphQLObjectType({ | ||
name: '_Service', | ||
fields: { | ||
sdl: { | ||
type: GraphQLInt, | ||
}, | ||
}, | ||
}), | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
expect(schemaIsSubgraph(schema)).toBe(false); | ||
}); | ||
|
||
it('returns false when the sdl field is a scalar', async () => { | ||
const schema = new GraphQLSchema({ | ||
query: new GraphQLObjectType({ | ||
name: 'QueryType', | ||
fields: { | ||
_service: { | ||
type: new GraphQLObjectType({ | ||
name: '_Service', | ||
fields: { | ||
sdl: { | ||
type: new GraphQLObjectType({ | ||
name: 'Scalar', | ||
fields: { | ||
value: { | ||
type: GraphQLString, | ||
}, | ||
}, | ||
}), | ||
}, | ||
}, | ||
}), | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
expect(schemaIsSubgraph(schema)).toBe(false); | ||
}); | ||
|
||
it('returns true when the sdl field is a string', async () => { | ||
const schema = new GraphQLSchema({ | ||
query: new GraphQLObjectType({ | ||
name: 'QueryType', | ||
fields: { | ||
_service: { | ||
type: new GraphQLObjectType({ | ||
name: '_Service', | ||
fields: { | ||
sdl: { | ||
type: GraphQLString, | ||
}, | ||
}, | ||
}), | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
expect(schemaIsSubgraph(schema)).toBe(true); | ||
}); | ||
|
||
it('returns true when the sdl field is a non nullable string', async () => { | ||
const schema = new GraphQLSchema({ | ||
query: new GraphQLObjectType({ | ||
name: 'QueryType', | ||
fields: { | ||
_service: { | ||
type: new GraphQLObjectType({ | ||
name: '_Service', | ||
fields: { | ||
sdl: { | ||
type: new GraphQLNonNull(GraphQLString), | ||
}, | ||
}, | ||
}), | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
expect(schemaIsSubgraph(schema)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters