Hi,
Am trying to use @inaccessible directive, but i get GraphQLError: Unknown directive “inaccessible”
Is this directive still valid?
thanks
-Vasu
Hi,
Am trying to use @inaccessible directive, but i get GraphQLError: Unknown directive “inaccessible”
Is this directive still valid?
thanks
-Vasu
Is there anyone who can help me with this question please?
Hello
@inaccessible
is a valid federation v2 directive (docs → Federation-specific GraphQL directives - Apollo GraphQL Docs).
Make sure that library/framework you are using actually provides support for it though → Federation-compatible subgraph implementations - Apollo GraphQL Docs
Thanks,
Derek
thanks for the reply @dkuc , I tried this below subgraph. I think am unable to import the federation 2 schema . Can you please help
extend schema @link(url: "https://specs.apollo.dev/federation/v2.3",as: "fed")
type Post @key(fields: "id") {
id: ID!
title: String!
author: User @provides(fields: "name")
content: String! @inaccessible(reason:"Private var")
}
extend type User @key(fields: "id") {
id: ID! @external
posts: [Post]
name : String! @external
}
extend type Query {
post(id: ID!): Post
posts: [Post]
}
I get this error when i try to start
/Users/graphql_pox/posts/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:49
throw new GraphQLSchemaValidationError_1.GraphQLSchemaValidationError(errors);
^
GraphQLSchemaValidationError: Unknown directive "@link".
What versions of the libraries are you using? Make sure that you are using latest versions of the libs to ensure all federation features are supported.
Your @link
directive should be importing federation directives, i.e.
@link(url: "https://specs.apollo.dev/federation/v2.3", import: [ "@external", "@inaccessible", "@key", "@provides"]
Few additional comments:
federation__
, e.g. @federation__key
). Guessing you probably don’t need custom namespace (i.e. as: “fed” which would result in @fed__key
) so I’d drop it.extend type
/@extends
were required in federation v1 and there is no need for it in federation v2 (you may want to keep the extend schema
part so you don’t have to redefine default query/mutation fields).@external
on @key
fields (it was required in v1) - you can safely drop it from User.id
fieldUser.name
is only reachable through @provides
path, this field will always be resolved locally so you don’t need @external
there either (it was required in v1) - IF this field is reachable in this graph through some other path without @provides
then keep the @external
const { ApolloServer } = require('apollo-server');
const {gql} = require('graphql-tag');
const { buildFederatedSchema} = require('@apollo/federation');
const { PostsAPI,UsersAPI } = require('./postsapi.js');
const {LoggerPlugin} = require('./logger.js')
const typeDefs = gql`
type Post @key(fields: "id") {
id: ID!
title: String!
author: User @provides(fields: "name")
content: String!
}
extend type User @key(fields: "id") {
id: ID! @external
posts: [Post]
name : String! @external
}
extend type Query {
post(id: ID!): Post
posts: [Post]
}
`;
const resolvers = {
//<some code here>
};
const schema = buildFederatedSchema([{ typeDefs, resolvers }]);
const server = new ApolloServer({
plugins : [LoggerPlugin],
schema: buildFederatedSchema([{ typeDefs, resolvers }]),
dataSources: () => ({
postsAPI: new PostsAPI(),
usersAPI: new UsersAPI()
}),
});
server.listen({host:"0.0.0.0",port:6002}).then(({ url }) => {
console.log(`🚀 Subgraph ready at ${url}`);
});
Looks like @apollo/federation doesnt have these directives. @apollo/subgraph or @apollo/federation-internals has it. Should I use buildFederatedSchema or buildSubGraphSchema for a subgraph?
Any pointers to documentation will be helpful
I was able to get it working. Thanks for the help.