Custom Resolvers

The library will autogenerate Query and Mutation resolvers, so you don’t need to implement those resolvers yourself. However, if you would like additional behaviours besides the autogenerated CRUD operations, you can specify custom resolvers for these scenarios.

1. Custom object type field resolver

If you would like to add a field to an object type which is resolved from existing values in the type, rather than storing new values, you should mark it with an @ignore directive and define a custom resolver for it.

const typeDefs = `
    type User {
        firstName: String!
        lastName: String!
        fullName: String! @ignore
    }
`;

const resolvers = {
    User: {
        fullName(obj) {
            return `${obj.firstName} ${obj.lastName}`;
        },
    },
};

const neoSchema = new Neo4jGraphQL({
    typeDefs,
    resolvers,
});

2. Custom Query/Mutation type field resolver

You can define additional, custom Queries and Mutations in your type definitions and provide custom resolvers for them. A prime use case for this is using the OGM to manipulate types and fields which are not available through the API.

const typeDefs = `
    type User {
        userId: ID!
    }

    type Query {
        users: [User]
    }
`;

const resolvers = {
    Query: {
        users: () => // implement resolver here
    }
};

const neoSchema = new Neo4jGraphQL({
    typeDefs,
    resolvers,
});