本文介绍了GraphQLError:语法错误:预期:,找到{的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 graphql 查询/突变.

Here are my graphql queries / mutations.

我收到错误:GraphQLError:语法错误:预期:,找到{

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
        }
    }
`;

推荐答案

这是第二个查询.你需要改变这个

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

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

为此:

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

input

这篇关于GraphQLError:语法错误:预期:,找到{的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 13:47