Adam J.R. Erickson
Adam J.R. Erickson

Reputation: 1840

GraphQL arguments to connection sub results

I'm need help passing arguments to collections/connections/arrays in GraphQL syntax.

I'm just learning it, playing with the SWAPI at http://graphql.org/swapi-graphql/

I can pass an id argument to a single type, like this:

query getANewHope {
  film(id: "ZmlsbXM6MQ==") {
    id
    title
  }
}

But I don't know how to query the results of a collection/connection

query starships {
  allStarships(id: "c3RhcnNoaXBzOjI=") { # this doesn't work
    edges {
      node(id: "c3RhcnNoaXBzOjI=") { # ...nor this.
        id
      }
    }
  }
}

I want to query collections because, I'd like to connect the two ideas like "All Starfighter type ships in A New Hope"?

query filmStarships {
  film(id: "ZmlsbXM6MQ==") {
    title
    starshipConnection { #How to limit this?  I can't use (starshipClass: "Starfighter") here...
      edges {
        node { # ...nor here..
          starshipClass # ...nor here.
        }
      }
    }
  }
}




query starships2 {
  starship (id:  "c3RhcnNoaXBzOjI=") { # This doesn't work either
    id # even without an arugment abovce, it says "Unknown argument \"id\" on field \"node\" of type \"StarshipsEdge\"."
  } 
}

Upvotes: 0

Views: 268

Answers (1)

ECWyne
ECWyne

Reputation: 433

Arguments like you're asking for have to be implemented in the schema. The SWAPI does does not expose an argument to filter by starshipClass. Click Docs on the top right of the GraphiQL window to explore the provided schema.

If you are implementing your own schema it would be very easy to add a filter on starshipClass in the resolvers.

Upvotes: 1

Related Questions