Skip to content
This repository has been archived by the owner on Aug 9, 2018. It is now read-only.

creativemarket/qld2

Repository files navigation

Go go gadget GraphQL

Make sure you have PHP installed outside the VM:

php -v

If not:

brew install homebrew/php/php72

Install packages:

npm install

Run the graph server via command line:

php -S localhost:8080 ./graphql.php

Run the dev server separately (both servers runnning):

npm run server

Browser + docs

GraphiQL is an in-browser tool for exploring GraphQL APIs. I did not want to mess with setting all that up, so I just installed a Chrome extension for it (I used this one).

Either way, it will allow you to play around with the API without any other tools, AND it parses the GraphQL types and provides documentation of the schema, which is super fancy.

Set your server to http://localhost:8080

Queries

The GraphQL docs will explain this better than I can.

Sample query

TODO: There are a bunch of default types not represented in this data set. Also, it only supports queries (not mutations).

The following query returns pretty much all of the sample data, which can be found (and added to!) in /StarWar/Data/DataSource.php.

{
  viewer {
    ...charData
  }
  rey: character(id: 1) {
    ...charData
  }
  leia: character(id: 2) {
		...charData
  }
  maz: character(id: 3) {
    ... charData
  }
  movies {
    title
    totalQuoteCount
    quotes(after: 1) {
      ... quoteInfo
      replies {
        ... quoteInfo
      }
    }
  }
  lastMoviePosted {
    title
  }
}

fragment charData on Character {
    email
    firstName
    lastName
}

fragment quoteInfo on Quote {
  body
  character {
    ... charData    
  }
  totalReplyCount
}

Sample mutation with input object

mutation Mutation($quoteInput: QuoteInput!) {
  createQuote(quoteInput: $quoteInput) {
    body
    character {
      firstName
    }
  }
}
# variables
{
	"quoteInput": {
	  "characterId": 2,
	  "movieId": 1, 
	  "body": "make me a new quote!"
	}
}

Vendor docs

GraphQL

GraphQL-PHP

Releases

No releases published

Packages

No packages published