我有
export const getPicture = {
type: GraphPicture,
args: {
type: new GraphQLNonNull(GraphQLInt)
},
resolve(_, args) {
return Picture.findByPrimary(args.id);
}
};
export const getPictureList = {
type: new GraphQLList(GraphPicture),
resolve(_, __, session) {
return Picture.findAll({where: {owner: session.userId}});
}
};
和
const query = new GraphQLObjectType({
name: 'Queries',
fields: () => {
return {
getPictureList: getPictureList,
getPicture: getPicture
}
}
});
const schema = new GraphQLSchema({
query: query,
mutation: mutation
});
引发:
Error: Queries.getPicture(type:) argument type must be Input Type but got: undefined.
getPictureList工作正常,getPicture失败。
我试过让getPicture成为GraphQLLIst,没有帮助。
我尝试将args类型设为输入类型,但没有帮助。
关于这里发生了什么的任何想法
堆栈跟踪是:
Error: Queries.getPicture(type:) argument type must be Input Type but got: undefined.
at invariant (/home/jrootham/dev/trytheseon/node_modules/graphql/jsutils/invariant.js:19:11)
at /home/jrootham/dev/trytheseon/node_modules/graphql/type/definition.js:307:33
at Array.map (native)
at /home/jrootham/dev/trytheseon/node_modules/graphql/type/definition.js:304:52
at Array.forEach (native)
at defineFieldMap (/home/jrootham/dev/trytheseon/node_modules/graphql/type/definition.js:293:14)
at GraphQLObjectType.getFields (/home/jrootham/dev/trytheseon/node_modules/graphql/type/definition.js:250:46)
at /home/jrootham/dev/trytheseon/node_modules/graphql/type/schema.js:224:27
at typeMapReducer (/home/jrootham/dev/trytheseon/node_modules/graphql/type/schema.js:236:7)
at Array.reduce (native)
at new GraphQLSchema (/home/jrootham/dev/trytheseon/node_modules/graphql/type/schema.js:104:34)
at Object.<anonymous> (/home/jrootham/dev/trytheseon/server/graphQL.js:45:16)
at Module._compile (module.js:399:26)
at normalLoader (/usr/lib/node_modules/babel/node_modules/babel-core/lib/babel/api/register/node.js:160:5)
at Object.require.extensions.(anonymous function) [as .js] (/usr/lib/node_modules/babel/node_modules/babel-core/lib/babel/api/register/node.js:173:7)
at Module.load (module.js:345:32)
at Function.Module._load (module.js:302:12)
at Module.require (module.js:355:17)
at require (internal/module.js:13:17)
at Object.<anonymous> (/home/jrootham/dev/trytheseon/devServer.js:14:44)
at Module._compile (module.js:399:26)
at normalLoader (/usr/lib/node_modules/babel/node_modules/babel-core/lib/babel/api/register/node.js:160:5)
答案 0 :(得分:13)
问题不在于查询的返回类型,而在于您为args指定的类型。
<ion-header-bar class="bar-positive">
<button class="icon ion-home button button-clear"></button>
<h1 class="title">vivalooks</h1>
<button class="icon ion-person button button-clear"></button>
</ion-header-bar>
<div class="bar bar-subheader item-input-inset bar-light">
<label class="item-input-wrapper">
<i class="icon ion-search placeholder-icon"></i>
<input type="search" placeholder="Search">
</label>
</div>
<ion-view>
<ion-content class="has-subheader">
<ion-list class="list-inset" ng-repeat="items in keeps">
<ion-item class="item-text-wrap">
<div class="thumbnails_v"> <img ng-src="http://localhost/vivalooks/resize_image/vivalooks.php?image={{item.pic}}&new_width=300&new_height=300"">
</div>
<p>
{{item.fname}} {{item.lname}}
</p>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
假设你想要一个名为&#34的参数;输入&#34;它应该是:
export const getPicture = {
type: GraphPicture,
args: {
type: new GraphQLNonNull(GraphQLInt)
},
resolve(_, args) {
return Picture.findByPrimary(args.id);
}
};
这是graphql-js repo的一个例子:
export const getPicture = {
type: GraphPicture,
args: {
type: {
type: new GraphQLNonNull(GraphQLInt)
}
},
resolve(_, args) {
return Picture.findByPrimary(args.id);
}
};
请参阅graphql-js repo中的完整架构:https://github.com/graphql/graphql-js/blob/master/src/tests/starWarsSchema.js
答案 1 :(得分:11)
仅供参考,我在这里搜索相同的错误,但不是undefined
,而是使用我自己的Product
类型:
... argument * must be Input Type but got Product
原来在GraphQL中传递给Mutation的内容应该是标量类型(String,Integer,...)或用户定义的 input
类型,而不是{{1} }类型。
http://graphql.org/graphql-js/mutations-and-input-types/
type
我试图传递我的产品input ProductInput {
id: ID
name: String
}
:
type
这感觉有点多余,但猜测,我很高兴以后将它分开。