Symfony GraphQL API
This module is to be used to create a list of locations by users - we can assume, that it is about Events that will take place at the address indicated and will last at the specified address time interval (date from - to). The module returns a list of added events, and the user can find any by entering the name of the event in the search engine.
env options (.env.local)
APP_ENV
DATABASE_URL
DEV_CLIENT_API_TOKEN
API_ITEMS_PER_PAGE
Install
composer install
php bin/console doctrine:database:create
php bin/console doctrine:schema:update --force
php bin/console doctrine:fixtures:load --append --group=users
Create API user
php bin/console app:create-api-user username api_key
Show API Token
php bin/console app:show-api-user-token username
Start server
sh start_server.sh
Tests
php ./vendor/bin/phpunit
Queries
Events List:
query {
events_list(limit:100, page:1) {
events {
id
name
slug
email
streetAddress
city
country
zipcode
dateFrom
dateTo
}
}
}
Single Event:
query {
event(id:"bca2bbaf-f44e-4e06-a6cb-4922ccf245da") {
id
name
slug
email
streetAddress
city
country
zipcode
dateFrom
dateTo
}
}
Events Search:
query {
events_search(phrase:"Impreza") {
events {
id
name
slug
email
streetAddress
city
country
zipcode
dateFrom
dateTo
}
}
}
Mutations
Create Event
mutation {
event_create(input: {
name: "Jakieś wydarzenie"
streetAddress: "al. Warszawska 12"
country: "PL"
city: "Olsztyn"
zipcode: "10-082"
email: "jan@kowalski.dev"
dateFrom: "2020-01-01"
dateTo: "2020-02-25"
}) {
id
}
}
Client for dev
After start server open http://localhost:3000/graphiql
.
Elasticsearch
Check Elasticsearch status. Should be active.
sudo systemctl status elasticsearch
Check Elasticsearch version:
curl http://localhost:9200
Required 7.* for this project.
Create indexes
You need to create the indexes in Elasticsearch. This can be easily done running the following command:
php bin/console fos:elastica:create
Populate data
You can populate the information of the table in Elasticsearch running the following command:
php bin/console fos:elastica:populate
Bibliography
- Introduction to GraphQL
- Quick start
- Schema
- Resolver
- Debug
- Access control in GraphQL using Symfony
- Annotations & PHP 8 attributes
- Annotations reference
- Validation
- The Arguments Transformer service
- Optimizations for entity fetching for Doctrine ORM to address N+1 queries problem
- Client GraphiQL
- Adding a GraphQL API to your Symfony Flex application
- How to create your search engine with Elasticsearch 7 and FOSElasticaBundle in Symfony 5
Copyrights
Copyright (c) Rafał Mikołajun 2021.