Are nested GraphQL queries with specific id values possible?

Viewed 7773

I've successfully built a GraphQL API which allows nested queries. Using the generic examples of Countries & States, I can perform a query like this:

    query{
      country(id:"Q291bnRyeTo0Nw==") {
        states {
          edges {
            node {
              id,
              name,
              area,
              population
            }
          }
        }
       }
     }

What I've discovered I can't seem to do is this:

query{
      country(id:"Q291bnRyeTo0Nw==") {
        state(id:"U3RhdGU6MzM=") {
          edges {
            node {
              id,
              name,
              area,
              population
            }
          }
        }
      }
    }

Might there be a way with GraphQL to specify a specific parent and specific child in one query?

Robert

Update: For Daniel's benefit, here is my current GraphQL Query code:

from .models import Country as CountryModel
from .models import State as StateModel

class Query(graphene.AbstractType):

    country = graphene.Field(Country, id=graphene.String())
    countries = graphene.List(Country)

    state = graphene.Field(State, id=graphene.String())
    states = graphene.List(State)

    def resolve_country(self, args, context, info):
        id = args.get('id')

        if id is not None:
            return CountryModel.objects.get(id=Schema.decode(id))
    
        return None

    def resolve_countries(self, args, context, info):
        return CountryModel.objects.all()

    def resolve_state(self, args, context, info):
        id = args.get('id')

        if id is not None:
            return StateModel.objects.get(id=Schema.decode(id))
    
        return None

    def resolve_states(self, args, context, info):
        return StateModel.objects.all()

1 Answers
Related