如何在graphQL Schema中使用中继连接进行变异

时间:2017-02-28 04:54:53

标签: javascript graphql relayjs relay graphql-js

我正在尝试在GraphQL架构中使用graphql-relay connectionDefinitions以便添加Edges&我的变异中的节点调用。

我的项目背景:我有自定义字段对象,我需要更新并显示以下变异调用

    const CustomFieldDefinition = new GraphQLInputObjectType({
                name: 'CustomFieldDefinitions',
                fields: {
                    schem: {
                        type: GraphQLString
                    },
                    deleted: {
                        type: GraphQLBoolean
                    },
                    associatedEntityTypes: {
                        type: GraphQLString
                    },
                    name: {
                        type: GraphQLString
                    },
                    id: {
                        type: GraphQLID
                    }
                }
            })

    const { connectionType: Common_CustomFieldDefinitionConnection } =
            connectionDefinitions({
                   name: 'Common_CustomFieldDefinitionEdge',
                   nodeType: CustomFieldDefinition
        });

    const createCommon_CustomFieldDefinition = mutationWithClientMutationId({
        name: 'CreateCommon_CustomFieldDefinition',
        inputFields: {
            customFieldDefinition: {type: Common_CustomFieldDefinitionConnection},
            clientMutationId: {type: GraphQLString}
        },
        outputFields: {
            customFieldDefinition: {
                type: CustomFieldDefinition,
                resolve: (obj) => {
                    return (obj.customFieldDefinitions[obj.customFieldDefinitions.length-1])
                }
            }
        },
        mutateAndGetPayload: (params) => {
            return Promise.resolve(
                updateCustomField(params)   // Think of it as a method which update all custom fields.
            );
        }
    });

    const Mutation = new GraphQLObjectType({
            name: 'Mutation',
            fields: {
                createCommon_CustomFieldDefinition: createCommon_CustomFieldDefinition
            }
        });

    const mySchema = new GraphQLSchema({
        mutation: Mutation
    });

    module.exports = mySchema;

这是Mutation调用,我试图让它工作

mutation {
  createCommon_CustomFieldDefinition(input:{
    clientMutationId: "1442",
    commonCustomFieldDefinition: {
         name: "Vamsi_date",
         schem: "Anything",
         associatedEntityTypes :"CUSTOMER"
    }
 }) {
    clientMutationId
    commonCustomFieldDefinitionEdge{
      node{
        name
        id
        schem
       }
    }
  }
}

我面临的问题是每当我启动服务器时,我都会收到错误

Error: CustomFieldDefinition.customFieldDefinitions field type must be Input Type but got: Common_CustomFieldDefinitionEdgeConnection.

你能帮我解决这个问题。我认为我在下面的代码中做错了。

const { connectionType: Common_CustomFieldDefinitionConnection } =
            connectionDefinitions({
                   name: 'Common_CustomFieldDefinitionEdge',
                   nodeType: CustomFieldDefinition
        }); 

0 个答案:

没有答案