timkippdev/graphql-starter-project

Starter project for working with the PHP GraphQL library

1.0.0 2019-01-13 07:21 UTC

This package is auto-updated.

Last update: 2024-11-13 21:17:22 UTC


README

This starter project was derived from the graphql-php "Getting Started" documentation example.

Project Installation

Install with Composer

composer create-project timkippdev/graphql-starter-project --prefer-dist

Development Setup using Docker (optional)

This assumes you have Docker installed and running on your machine

Starting your Docker container

docker-compose up -d

If you need to run any composer commands, you use run them against the composer container:

docker-compose run --rm composer <insert command here>

If you need to log into your Docker container, run the following command and you will be launched into a shell inside the container:

docker exec -it graphql-starter-project bash

Executing a GraphQL Query

There are multiple ways to do this, but here are a couple to get started:

  1. Use GraphiQL, either web-based or a standalone application.
  2. Use either cURL or a REST client to fire a POST request

For either method you chose above, you will POST your request to http://localhost:8080/, if Docker was used, or the URL you have set up for your local development

GraphiQL Query Example

query {
  echo(message: "Hello World")
}

cURL / REST Payload Example

  1. cURL example
curl http://localhost:8080 -d '{"query": "query { echo(message: \"Hello World\") }" }'
  1. REST Client example

Content-Type: application/json
Method: POST
Payload (below):

{ "query": "query { echo(message: \"Hello World\") }" }

Expected Result

In either way you choose to execute your query, you should see a similar response to the following:

{
  "data": {
    "echo": "Hello World"
  }
}