GraphiQL 中的未知参数试图将 ID 从客户端传递到 GraphQL 服务器?

Unknown argument in GraphiQL trying to pass an ID from the client to the GraphQL server?

我正在使用 Apollo 2。通过 GraphiQL 界面,我可以 运行 一个查询,returns 所有组都可以。但是,当我尝试传递一个名称以仅查找 1 个组时,它确实有效。

架构

type Query {
    hi: String
    groups: [Group]
    group(name: String): Group
}

type Group {
    name: String
}

解析器:

Query: {
        hi() {
            return 'howdy';
        },
        groups() {
            return Groups.find().fetch();
        },
        group(one, two, three) {
            console.log('group resolver called');
            console.log(one, two, three);
            //return Groups.findOne(two.name);
        },
    },

这是我的 GraphiQL 组查询,运行良好:

{
  groups {
    name
  }
}

但是我的群查询returns出错:

{
  group(name: "some name") {
    name
  }
}

{
  "errors": [
    {
      "message": "Unknown argument \"name\" on field \"group\" of type \"Query\".",
      "locations": [
        {
          "line": 2,
          "column": 9
        }
      ]
    }
  ]
}

更新 - 这是我的完整文件:

import { createApolloServer } from 'meteor/apollo';
import { makeExecutableSchema } from 'graphql-tools';
import merge from 'lodash/merge';

import GroupsSchema from '../../api/groups/Groups.graphql';
import GroupsResolvers from '../../api/groups/resolvers';

const typeDefs = [GroupsSchema];
const resolvers = merge(GroupsResolvers);

const schema = makeExecutableSchema({
    typeDefs,
    resolvers,
});

createApolloServer({ schema });

在resolvers.js

import Groups from './groups';

export default {
    Query: {
        hi() {
            return 'howdy';
        },
        groups() {
            return [{ name: '1', test: 'test 1' }, { name: '2', test: 'test 2' }];
            // return Groups.find().fetch();
        },
        group(one, two, three) {
            console.log('group resolver called');
            console.log(one, two, three);
            // return Groups.findOne('Apon9HKE9MeZqeXsZ');
        },
    },
};

在Groups.graphql

type Query {
    hi: String
    groups: [Group]
    group(name: String): Group
}

type Group {
    name: String
}

我认为你的 typeDef 和解析器是错误的,试试:

typeDefs

const typeDefs = `
  type Query {
    hi: String
    groups: [Group]
    group(name: String): Group
}

type Group {
    name: String
}`;

解析器

export default {
        Query: {
            hi() {
                return 'howdy';
            },
            groups() {
                return [{ name: '1', test: 'test 1' }, { name: '2', test: 'test 2' }];
                // return Groups.find().fetch();
            },
            group(_, { name }) {
                console.log('group resolver called');
                console.log(one, two, three);
                // return Groups.findOne('Apon9HKE9MeZqeXsZ');
            },
        },
    };