From 583ebb7bd8bec73df5957da7f360559091804801 Mon Sep 17 00:00:00 2001 From: Kristian Freeman Date: Mon, 4 Nov 2024 11:10:58 -0600 Subject: [PATCH] Add example mutation --- graphql.schema.json | 65 ++++++++++++++++++++++++++++++++++++++++++++- src/resolvers.ts | 6 +++++ src/schema.graphql | 4 +++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/graphql.schema.json b/graphql.schema.json index 362f349..2e1b6b4 100644 --- a/graphql.schema.json +++ b/graphql.schema.json @@ -3,7 +3,9 @@ "queryType": { "name": "Query" }, - "mutationType": null, + "mutationType": { + "name": "Mutation" + }, "subscriptionType": null, "types": [ { @@ -115,6 +117,67 @@ "enumValues": null, "possibleTypes": null }, + { + "kind": "OBJECT", + "name": "Mutation", + "description": null, + "isOneOf": null, + "fields": [ + { + "name": "add", + "description": null, + "args": [ + { + "name": "numberOne", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "numberTwo", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + } + ], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, { "kind": "OBJECT", "name": "Pokemon", diff --git a/src/resolvers.ts b/src/resolvers.ts index dc9e033..76d6699 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -4,6 +4,12 @@ import PokemonAPI from './utils/pokeapi' const createResolvers = (context: Context): Resolvers => { return { + Mutation: { + add: async (_parent, { numberOne, numberTwo }, { cache }) => { + return numberOne + numberTwo + }, + }, + Query: { movies: async () => { // You can access the context object to access any diff --git a/src/schema.graphql b/src/schema.graphql index fdddd5b..c04373c 100644 --- a/src/schema.graphql +++ b/src/schema.graphql @@ -28,3 +28,7 @@ type Query { movies: [Movie!]! pokemon(id: ID!): Pokemon } + +type Mutation { + add(numberOne: Int!, numberTwo: Int!): Int! +}