I'd like to make every field private, unless otherwise notated with a directive. Is it possible to get this information within a resolve function?
const typeDefs = gql`
directive @public on FIELD_DEFINITION
type Query {
viewer: User @public
secret: String
}
type User {
id: ID!
}
`
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
addSchemaLevelResolveFunction(schema, (parent, args, params, info) => {
// Not possible
if (info.fieldName.directive === 'public') {
return parent;
}
throw new Error('Authentication required...');
});
const server = new ApolloServer({ schema });