1

Is there a way to tell makeExecutableSchema from graphql-tools to ignore certain directives?

I want to query my neo4j database with graphql. I also want to be able to specify subtypes in graphql. There is a library called graphql-s2s which adds subtypes to graphql. The library neo4j-graphql-js uses custom directives (@cyper and @relation) to build an augmented Schema. It takes typeDefs or an executableSchema from graphql-tools. qraphql-s2s lets me create an executableSchema out of the Schema containing subtypes. My hope was that I should be easy to just pipe the different schema outputs into each other like in a decorator pattern.

Unfortunately this is apparently not how it works as I get a lot of parser error messages, which are not really descriptive.

Unfortunately I haven't found any Grandstack documentation where it is shown how to use augmentSchema() on an executableSchema with relations and cypher in it.

Is there a way how to do this?

Below my naive approach:

const { transpileSchema } = require('graphql-s2s').graphqls2s;
const { augmentSchema } = require('neo4j-graphql-js');
const { makeExecutableSchema} = require('graphql-tools');
const { ApolloServer} = require('apollo-server');

const driver = require('./neo4j-setup');

/** The @relation and @cypher directives don't make any sense here they are 
just for illustration of having directives that make sense to
'augmentSchema' and not to 'makeExecutableSchema' **/  

const schema = `
type Node {
    id: ID!
}

type Person inherits Node {
    firstname: String
    lastname: String @relation(name: "SOUNDS_LIKE", direction: "OUT") 
}

type Student inherits Person {
    nickname: String @cypher(
      statement: """ MATCH (n:Color)...some weird cypher query"""
    )
}

type Query {
  students: [Student]
}
`

const resolver = {
        Query: {
            students(root, args, context) {
                // Some dummy code
                return [{ id: 1, firstname: "Carry", lastname: "Connor", nickname: "Cannie" }]
            }
        }
    };

const executabledSchema = makeExecutableSchema({
  typeDefs: [transpileSchema(schema)],
  resolvers: resolver
})

const schema = augmentSchema(executabledSchema)

const server = new ApolloServer({ schema, context: { driver } });

server.listen(3003, '0.0.0.0').then(({ url }) => {
  console.log(`GraphQL API ready at ${url}`);
});
helpusobi
  • 23
  • 1
  • 6

0 Answers0