1

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?

noob
  • 74
  • 1
  • 8
  • only one type here, so no parent – xadm Apr 29 '20 at 13:26
  • @xadm could you please a bit more elaborate? Didn't understood what you meant. Here Employee is the node type and empId is property of which the resolver I need to override. – noob Apr 29 '20 at 14:44
  • parent arg is for types... Team > Employee ... employee resolver[-s] can access Team (his parent) properties – xadm Apr 29 '20 at 15:00
  • here my Employee node is the parent and empid is the prop. empid has access to parents objects but only the one that are part of the query fired. – noob Apr 30 '20 at 04:09
  • only in this case, if it is a root query ... use `params` to access db record then use it's iuid for rest... if not queried, no other way .... check parent iuid to bypass 1st step when already resolved – xadm Apr 30 '20 at 09:01
  • Ok for this scenario where whenever we query the Employee node, we want some of its node properties like say empname to come from some other db or external api. here in my neo4j DB i have a prop uid which is also present in my other DB from where i wish to fetch the empname from. So my requirement is if empname from Employee node is queried from graphql then it should somehow get the corressponding iuid from my neo4j that i would later use to make a rest call to get the empname. Is this thing possible to implement by any means? The query can also be without params. – noob Apr 30 '20 at 13:15
  • if you don't understand.... don't use generated code, write your own resolver for this type to learn how it works – xadm Apr 30 '20 at 13:41

0 Answers0