Using root object in graphql resolver function to access parent fields properties

941 Views Asked by At

I am using neo4j-graphql-js library to auto generate resolvers from the schema. For a node in the schema(Employee) i need to get a particular node property(empid) from a rest call as we plan to remove that property from our neo4j database due to privacy issues. I am trying to write a custom resolver for that field . I have added @neo4j directive to that field in the schema for neo4j to ignore it. I need to make a rest call that accepts a parameter named uid and returns the corressponding empid. This iuid is a property of Employee node and so is present in my neo4j DB. The issue is while writing the resolver the root objects only holds the filed values accesed in the query. So if iuid is not part of the query i'm unable to get it's value in the root obj. Here is my employee node: -

 type Employee{
 empId: String @neo4j_ignore
 buCode: String
 iuid: String
 name: String
 projectCode: String
 roleCode: String
 grade: String
 mailid: String
 duCode: String
 txtmailid_new: String

Here is my resolver where for my i am returning a dummy string instead of making a rest call: -

    
const resolvers={
   
    Employee: {
        empId: async (obj, params, ctx, resolveInfo) => {
            console.log(obj.iuid);
            var result="dummy_emp_id";
            return result;
        }
    }
};



const schema = makeAugmentedSchema({ typeDefs, resolvers} );
  
const server = new ApolloServer({ schema, context: { driver } });
server.listen(3003, '127.0.0.1').then(({ url }) => {
    console.log(`GraphQL API ready at ${url}`);
  });

Here is my query:- {

Employee(first : 10)
{
    empId                                                          
    name


}

}

I want to access all the value of all the field of the employee node so i can get the iuid.The console log returns undefined as the root object only has the queried field. I don't know even if it is possible and if not is there any workaround this?

0

There are 0 best solutions below