Archived course lesson

Add GraphQL request files

Part of Frontend Serverless with React and GraphQL

Objective: Add the queries and mutations that we will use in the rest of the app.

[Click to download the graphQL files](/downloads/frontend-serverless-graphql.zip)

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:

npm install --save graphql-tag
import gql from 'graphql-tag';

export const createRecipeGraphQL = gql`
  mutation createRecipeGraphQL($data: RecipeCreateInput!) {
    createRecipe(data: $data) {
      id
      title
      content
      description
      ingredients
      userLikes {
        id
      }
      owner
      image {
        id
        fileName
        height
        width
        size
        handle
      }
    }
  }
`;
import gql from 'graphql-tag';

export const createUserLikeGraphQL = gql`
  mutation createUserLikeGraphQL($data: UserLikeCreateInput!) {
    createUserLike(data: $data) {
      id
      user
      recipe {
        id
      }
    }
  }
`;
import gql from 'graphql-tag';

export const deleteAssetGraphQL = gql`
  mutation deleteAssetGraphQL($where: AssetWhereUniqueInput!) {
    deleteAsset(where: $where) {
      id
    }
  }
`;
import gql from 'graphql-tag';

export const deleteRecipeGraphQL = gql`
  mutation deleteRecipeGraphQL($where: RecipeWhereUniqueInput!) {
    deleteRecipe(where: $where) {
      id
    }
  }
`;
import gql from 'graphql-tag';

export const deleteUserLikeGraphQL = gql`
  mutation deleteUserLikeGraphQL($where: UserLikeWhereUniqueInput!) {
    deleteUserLike(where: $where) {
      id
      user
    }
  }
`;
import gql from 'graphql-tag';

export const updateRecipeGraphQL = gql`
  mutation updateRecipeGraphQL(
    $data: RecipeUpdateInput!
    $where: RecipeWhereUniqueInput!
  ) {
    updateRecipe(data: $data, where: $where) {
      id
      title
      content
      description
      ingredients
      userLikes {
        id
      }
      owner
      image {
        id
        fileName
        height
        width
        size
        handle
      }
    }
  }
`;
import gql from 'graphql-tag';

export const recipeGraphQL = gql`
  query recipeGraphQL($where: RecipeWhereUniqueInput!) {
    recipe(where: $where) {
      id
      title
      content
      description
      ingredients
      userLikes {
        id
        user
      }
      owner
      image {
        id
        fileName
        height
        width
        size
        handle
      }
    }
  }
`;
import gql from 'graphql-tag';

export const recipesGraphQL = gql`
  query recipesGraphQL($where: RecipeWhereInput) {
    recipes(where: $where) {
      id
      title
      content
      description
      ingredients
      userLikes {
        id
        user
      }
      owner
      image {
        id
        fileName
        height
        width
        size
        handle
      }
    }
  }
`;
import gql from 'graphql-tag';

export const userLikeGraphQL = gql`
  query userLikeGraphQL($where: UserLikeWhereUniqueInput!) {
    userLike(where: $where) {
      id
      user
      recipe {
        id
        title
        content
        description
        ingredients
        userLikes {
          id
          user
        }
        owner
        image {
          id
          fileName
          height
          width
          size
          handle
        }
      }
    }
  }
`;
import gql from 'graphql-tag';

export const userLikesGraphQL = gql`
  query userLikesGraphQL($where: UserLikeWhereInput) {
    userLikes(where: $where) {
      id
      user
      recipe {
        id
        title
        content
        description
        ingredients
        userLikes {
          id
          user
        }
        owner
        image {
          id
          fileName
          height
          width
          size
          handle
        }
      }
    }
  }
`;