cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

GraphQL implementing custom resolver field

Hello,
I'm trying out GraphQL. I can use the generated resolvers using Neo4j 3.15 without any issues. I'm now trying to create a custom resolver field based on this article https://grandstack.io/docs/guide-graphql-schema-design.html

I defined the resolver as below in the graphql-schema.js file:

export const resolvers = {
Test_User: {
fullDescription(object, params, ctx, resolveInfo) {
return ${object.description1} - ${object.description2};
}
}
};

and the type as follow in the schema.graphql. 'fullDescription' is a new resolver field not defined in Neo4j

type Test_User {
id: ID!
name: String
description1: String
description2: String
fullDescription: String
}

The query returns 'undefined' for the object parameter:

{
"data": {
"Test_User": [
{
"fullDescription": "undefined - undefined"
}
]
}
}

What am I doing wrong?

Thanks

1 REPLY 1

This is returning undefined as the object parameter of resolver function has all the properties of it's parent field that are also part of the query. Since in your case neither description1 nor description2 are part of the query so the object doesn't have these properties. You can print on console this object inside the resolver to know what field it holds.
export const resolvers = {
Test_User: {
fullDescription(object, params, ctx, resolveInfo) {
console.log(object);
return ${object.description1} - ${object.description2} ;
}
}
};