Symfony y GraphQL: Mutations

Aprende a desarrollar una API GraphQL con Symfony y GraphQLBndle

Paso 0. Definiendo la entidad ContactForm y su tipo en GraphQL

Paso 1. Definiendo una mutation

mutation {
createContactForm(input: {name: "Gerardo Fernández", email: "info@mail.com", telephone: "1212121", message: "ola"}) {
id
}
}
overblog_graphql:
definitions:
schema:
query: Query
mutation: Mutation
mappings:
auto_discover: false
types:
-
type: yaml
dir: "%kernel.project_dir%/config/graphql/types"
suffix: ~
mutation {
createContactForm(input: {name: "ola", email: "info", telephone: "1212121", message: "ola"}) {
id
}
}
{
"data": {
"createContactForm": {
"id": 5
}
}
}

Paso 2. Validando mutations

mutation {
createContactForm(input: {name: "ola", email: "i", telephone: "1212121", message: "ola"}) {
id
}
}
{
"errors": [
{
"message": "Invalid data set",
"extensions": {
"category": "formException"
},
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"createContactForm"
],
"trace": [
{
"file": "/Users/gerardofernandez/LatteAndCode/projects/
} ....
]
}
],
"data": {
"createContactForm": null
}
}
services:  App\GraphQL\Formatter\FormExceptionFormatter:    tags:      - { name: kernel.event_listener, event: graphql.error_formatting, method: onErrorFormatting }
{
"errors": [
{
"message": "Invalid data set",
"extensions": {
"category": "formException"
},
"path": [
"createContactForm"
],
"state": {
"email": [
"The email '\"i\"' is not a valid email."
]
},
"code": {
"email": [
"bd79c0ab-ddba-46cc-a703-a7a4b08de310"
]
}
}
],
"data": {
"createContactForm": null
}
}

¿Quieres recibir más artículos como este?

Entre paseo y paseo con Simba desarrollo en Symfony y React

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store