graphqlapollo-serverresolver

How to access data from grandparent in apollo graphql server?


I am trying to access data from grandparent in a grandchild resolver. How do I achieve this?

{
    field1
    field2 {
        child1 {
            grandchild1
        }
    }
}

I want to access field1 in grandchild1. How to go about that?


Solution

  • If you can directly pass field2 object as the parent arg of grandchild1.

    const resolvers = {
        Query : {
            field2      : {return field2 obj}
        },
        Field2: {
            child1      : {return field2 obj}
        },
        Child1: {
            grandchild1 : {access field2 values return grandchild1}
        }
      }