小编Jim*_*ham的帖子

GraphQL错误 - 参数类型必须是输入类型但得到:undefined

我有

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}});
    }
};
Run Code Online (Sandbox Code Playgroud)

const query = new GraphQLObjectType({
    name: 'Queries',
    fields: () => {
        return {
            getPictureList: getPictureList,
            getPicture: getPicture
        }
    }
});

const schema = new GraphQLSchema({
    query: query,
    mutation: mutation
});
Run Code Online (Sandbox Code Playgroud)

哪个投掷:

Error: Queries.getPicture(type:) argument type must be Input Type but …
Run Code Online (Sandbox Code Playgroud)

graphql

13
推荐指数
2
解决办法
1万
查看次数

从突变返回结果

我的直接问题是为什么不调用查询解析函数?

我怀疑是变异解析函数(有效)的返回值存在问题。那么,返回值应该是什么样的呢?

更高层次的问题是:GraphQL 中是否有一种标准的方式来注册新用户并处理用户已经存在的情况?

下面的方法是将用户的所有数据都放在会话数据中,只传回前端需要的数据。

/**
 * graphQL.js
 *
 * Created by jrootham on 18/04/16.
 *
 * Copyright © 2016 Jim Rootham
 */

import graphqlHTTP from "express-graphql";
import {
    graphql,
    GraphQLSchema,
    GraphQLObjectType,
    GraphQLString,
    GraphQLNonNull,
    GraphQLBoolean
} from 'graphql';
import {hash} from "bcrypt"
import {connect, User} from "../database/defineDB";

const GraphUser = new GraphQLObjectType({
    name: "GraphUser",
    description: "A user object",
    fields: () => {
        return {
            name: {
                type: GraphQLString,
                resolve: (_, __, session) => {
                    console.log("resolve name", session);
                    let name = …
Run Code Online (Sandbox Code Playgroud)

graphql graphql-js

5
推荐指数
1
解决办法
4169
查看次数

标签 统计

graphql ×2

graphql-js ×1