timkippdev / graphql-starter-project
Starter project for working with the PHP GraphQL library
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^7.1.3
- webonyx/graphql-php: ^0.13.0
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:
- Use GraphiQL, either web-based or a standalone application.
- 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
- cURL example
curl http://localhost:8080 -d '{"query": "query { echo(message: \"Hello World\") }" }'
- 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" } }