Frontend Serverless with React and GraphQL
Start at the beginning and work your way through this project. The code for each step as well as the finished project can be found in the Github repository.
12. Add GraphQL request files
Objective: Add the queries and mutations that we will use in the rest of the app.
This step is easy- just copy the following queries and mutations into the graphql/queries
and graphql/mutations
folders. Also make sure to install graphql-tag
:
bash
npm install --save graphql-tag
graphql/mutations/createRecipe.ts
import gql from 'graphql-tag';export const createRecipeGraphQL = gql`mutation createRecipeGraphQL($data: RecipeCreateInput!) {createRecipe(data: $data) {idtitlecontentdescriptioningredientsuserLikes {id}ownerimage {idfileNameheightwidthsizehandle}}}`;
graphql/mutations/createUserLike.ts
import gql from 'graphql-tag';export const createUserLikeGraphQL = gql`mutation createUserLikeGraphQL($data: UserLikeCreateInput!) {createUserLike(data: $data) {iduserrecipe {id}}}`;
graphql/mutations/deleteAsset.ts
import gql from 'graphql-tag';export const deleteAssetGraphQL = gql`mutation deleteAssetGraphQL($where: AssetWhereUniqueInput!) {deleteAsset(where: $where) {id}}`;
graphql/mutations/deleteRecipe.ts
import gql from 'graphql-tag';export const deleteRecipeGraphQL = gql`mutation deleteRecipeGraphQL($where: RecipeWhereUniqueInput!) {deleteRecipe(where: $where) {id}}`;
graphql/mutations/deleteUserLike.ts
import gql from 'graphql-tag';export const deleteUserLikeGraphQL = gql`mutation deleteUserLikeGraphQL($where: UserLikeWhereUniqueInput!) {deleteUserLike(where: $where) {iduser}}`;
graphql/mutations/updateRecipe.ts
import gql from 'graphql-tag';export const updateRecipeGraphQL = gql`mutation updateRecipeGraphQL($data: RecipeUpdateInput!$where: RecipeWhereUniqueInput!) {updateRecipe(data: $data, where: $where) {idtitlecontentdescriptioningredientsuserLikes {id}ownerimage {idfileNameheightwidthsizehandle}}}`;
graphql/queries/recipe.ts
import gql from 'graphql-tag';export const recipeGraphQL = gql`query recipeGraphQL($where: RecipeWhereUniqueInput!) {recipe(where: $where) {idtitlecontentdescriptioningredientsuserLikes {iduser}ownerimage {idfileNameheightwidthsizehandle}}}`;
graphql/queries/recipes.ts
import gql from 'graphql-tag';export const recipesGraphQL = gql`query recipesGraphQL($where: RecipeWhereInput) {recipes(where: $where) {idtitlecontentdescriptioningredientsuserLikes {iduser}ownerimage {idfileNameheightwidthsizehandle}}}`;
graphql/queries/userLike.ts
import gql from 'graphql-tag';export const userLikeGraphQL = gql`query userLikeGraphQL($where: UserLikeWhereUniqueInput!) {userLike(where: $where) {iduserrecipe {idtitlecontentdescriptioningredientsuserLikes {iduser}ownerimage {idfileNameheightwidthsizehandle}}}}`;
graphql/queries/userLikes.ts
import gql from 'graphql-tag';export const userLikesGraphQL = gql`query userLikesGraphQL($where: UserLikeWhereInput) {userLikes(where: $where) {iduserrecipe {idtitlecontentdescriptioningredientsuserLikes {iduser}ownerimage {idfileNameheightwidthsizehandle}}}}`;