GraphiQL中的未知参数试图将ID从客户端传递到GraphQL服务器?
我在用阿波罗2号。通过GraphiQL接口,我可以运行一个返回所有组的查询。然而,当我试图传递一个名称以仅查找一个组时,它不起作用 模式GraphiQL中的未知参数试图将ID从客户端传递到GraphQL服务器?,graphql,apollo-client,Graphql,Apollo Client,我在用阿波罗2号。通过GraphiQL接口,我可以运行一个返回所有组的查询。然而,当我试图传递一个名称以仅查找一个组时,它不起作用 模式 type Query { hi: String groups: [Group] group(name: String): Group } type Group { name: String } 解析程序: Query: { hi() { return 'howdy';
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
}
}
但是我的组查询返回一个错误:
{
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');
},
},
};
您是否尝试在您的冲突解决程序中将“组(一、二、三)”更改为“组(名称)”?我尝试了组(根,{name})和组(名称)。我收到了完全相同的错误消息。您可以添加文件的所有内容吗?解析程序和模式?@alesanderfrança完成了。我认为应该是group(root,{name}),但您已经告诉我这不起作用。为什么要在解析程序中导入组架构?