как решить вложенную мутацию graphql? - PullRequest
0 голосов
/ 15 марта 2019

Я новичок в graphql, и я не смог найти хорошего учебника для разрешения вложенных мутаций в graphql.Я попытался, как показано ниже, но получая неопределенную ошибку в дочерней части, при отправке в graphiQL.Я ценю любые предложения на этот счет.Спасибо.

                //Graphql  Schema part
                const Family = require("./models/Family");
                const { buildSchema } = require("graphql");
                const mongoose = require("mongoose");

                app.use(
                  "/api",
                  graphqlHttp({
                    schema: buildSchema(`
                    input ChildInput {
                        field1: String!
                        field2: String!
                    }
                    input ParentInput {
                        field3: String!
                        field4: String!
                        children: [ChildInput!]
                    }
                  type RootMutation{
                    createFamily(childInput: ChildInput, parentInput: ParentInput):Family
                  }
                schema{
                      mutation:RootMutation
                    }`),// resolver
                    rootValue: {
                    createFamily: args => {
                        const newfamily = new Family({
                            field3: args.parentInput.field3,
                            field4: args.parentInput.field4,
                            children:[{
                            field1: args.childInput.field1,
                            field2: args.childInput.field2
                            }]
                        });
                        return newfamily
                          .save()
                          .then(result => {
                            console.log(result);
                            return { ...result._doc };
                          })
                          .catch(err => {
                            throw err;
                          });
                },
                    graphiql: true
                  })
...