-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Federation SDL is invalid for non-Apollo tools #252
Comments
Yeah this has been annoying me for a bit, but I've been ignoring it. Does Apollo have any guidance here? |
The Apollo Federation spec says to include all uses of federation-specific directives but there's no mention of the directive definitions, although all of the spec examples omit the directive definitions. I followed the import gql from 'graphql-tag';
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone'
import { buildSubgraphSchema } from '@apollo/subgraph';
const typeDefs = gql`
extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable"])
type Query {
me: User
}
type User @key(fields: "id") {
id: ID!
username: String
}
`;
const resolvers = {};
const server = new ApolloServer({
schema: buildSubgraphSchema({ typeDefs, resolvers }),
});
const { url } = await startStandaloneServer(server, {
listen: { port: 4000 },
});
console.log(`🚀 Server ready at: ${url}`); Querying schema
@link(url: "https://specs.apollo.dev/link/v1.0")
{
query: Query
}
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable"])
directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA
directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
directive @federation__requires(fields: federation__FieldSet!) on FIELD_DEFINITION
directive @federation__provides(fields: federation__FieldSet!) on FIELD_DEFINITION
directive @federation__external(reason: String) on OBJECT | FIELD_DEFINITION
directive @federation__tag(name: String!) repeatable on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @federation__extends on OBJECT | INTERFACE
directive @shareable on OBJECT | FIELD_DEFINITION
directive @federation__inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @federation__override(from: String!) on FIELD_DEFINITION
type Query {
me: User
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type User
@key(fields: "id")
{
id: ID!
username: String
}
enum link__Purpose {
"""
`SECURITY` features provide metadata necessary to securely resolve fields.
"""
SECURITY
"""
`EXECUTION` features provide metadata necessary for operation execution.
"""
EXECUTION
}
scalar link__Import
scalar federation__FieldSet
scalar _Any
type _Service {
sdl: String
}
union _Entity = User So in summary, the Apollo tooling works fine with or without the directive definitions but their reference implementation does include the directives the |
@jturkel Interesting. Our sdl field calls our |
I'm not sure if this is intentional but the generated federation SDL is invalid for non-Apollo tools because it doesn't include the federation directive definitions. Here's a minimal reproducible test case:
This fails with the following exception:
I've confirmed graphql-js behaves the same way:
This fails with the following exception:
I've also confirmed that the Apollo tools work fine if the federation directive definitions are included in the SDL.
The text was updated successfully, but these errors were encountered: