Skip to content

Instantly share code, notes, and snippets.

@steezeburger
Last active April 18, 2018 22:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steezeburger/493831764cbf04250fcc5a81142c673e to your computer and use it in GitHub Desktop.
Save steezeburger/493831764cbf04250fcc5a81142c673e to your computer and use it in GitHub Desktop.
{query {allPeople}}

# If you try to run the above, Graphiql will expand it to:
{query {allPeople {edges {node {id}}}}}

# Navigating the help from: query → Person shows the full set of fields you can
# ask about each person. Tweak the above to:
{query {allPeople {edges {node {id firstName fullName}}}}}

# Navigating the help from root → query → allPeople → PeopleConnection shows
# that the autofilled value of `edges` is one of many, e.g., the following works too,
# and produces data in a slightly different shape:
{query {allPeople {nodes {id firstName fullName}}}}

# Nagivating the help from root → query → allPeople reveals you can parameterize the
# query itself by, e.g., first, last, offset, orderBy, etc:
{query {allPeople(first: 3, orderBy: LAST_NAME_DESC) {nodes {id firstName fullName}}}}

# Mutations: nagivating to root → mutation → registerPerson, I see (1) "Type" which
# turns out to be what the mutation returns, and (2) "Arguments" which is what the
# mutation needs.

# If you type in the following, mostly following autocomplete, a tooltip pops up
# saying the "input" needs firstName, lastName, etc.:
mutation {registerPerson(input: {})}

# So fill those in:
mutation {registerPerson(input:{firstName:"Mei", lastName:"Kusakabe", email:"mei@totoro.com", password:"nekobasu"})}

# If you run the above, Graphiql appends `{clientMutationId}` as the response from
# `registerPerson`, which will be null. Navigating the help from mutation → registerPerson
# → RegisterPersonPayload, we see that `clientMutationId` is the first on the list and
# probably why Graphiql autocompleted this return data. Looks like we can get `person`
# back too:

# Try the following:
mutation {registerPerson(input:{firstName:"Neko", lastName:"Basu", email:"nekobasu@totoro.com", password:"mei"}) {person {id}}}

# With the above as exposition, I was able to cobble together the following mutation:
mutation {createPost(input:{post:{authorId:11, headline:"Totoro rocks!", body:"¡Sure does!"}}) {clientMutationId}}
# I got `11` from the `allPeople` query.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment