Vinit Khandelwal
Vinit Khandelwal

Reputation: 627

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?

Upvotes: 0

Views: 494

Answers (1)

Ritz
Ritz

Reputation: 26

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}
    }
  }

Upvotes: 1

Related Questions