GraphQLError: Syntax Error: Expected :, found {

别等时光非礼了梦想. 提交于 2020-01-14 18:48:49

问题


Here are my graphql queries / mutations.

I'm getting the error: GraphQLError: Syntax Error: Expected :, found {

I don't know which one of them is wrong.

import gql from 'graphql-tag';

export const CategoriesQuery = gql`
    query categoriesQuery(
        $id: ID!,
        $country: String!,
        $name: String!
    ) {
        sections(
            id: $id,
            country: $country,
            name: $description
        ) {
            id,
            createdBy,
            createdDate,
            lastUpdate,
            name
        }
    }
`;

export const ItemsQuery = gql`
    query itemsQuery(
        $id: ID!,
        $category: String!,
        $url: String!,
        $alias: String!,
        $name: String!
    ) {
        items(
            input {
                id: $id,
                category: $category,
                url: $url,
                alias: $alias,
                name: $name
            }
        ) {
            id,
            createdBy,
            createdDate,
            lastUpdate,
            name,
            category,
            url,
            alias,
            description
        }
    }
`;

export const AddCategoryMutation = gql`
    mutation ($category: CategoryInput!) {
        addCategory(category: $category) {
            id
        }
    }
`;

export const AddItemMutation = gql`
    mutation ($item: ItemInput!) {
        addItem(item: $item){
            id
        }
    }
`;

回答1:


It's the second query. You need to change this

items(
  input {
      id: $id,
      category: $category,
      url: $url,
      alias: $alias,
      name: $name
  }
)

To this:

items(
  input: {
      id: $id,
      category: $category,
      url: $url,
      alias: $alias,
      name: $name
  }
)

Add a colon after input



来源:https://stackoverflow.com/questions/51877455/graphqlerror-syntax-error-expected-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!