Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom mutations and queries #25

Open
rpavez opened this issue May 4, 2017 · 1 comment
Open

Custom mutations and queries #25

rpavez opened this issue May 4, 2017 · 1 comment

Comments

@rpavez
Copy link

rpavez commented May 4, 2017

I had to check the source code to figure out how create custom mutations, it would be very helpful include better explanation on the docs.

It would be good mentioning that custom queries and mutations should be included in sequelize models definitions, then provide an example like this.

const user = sequelizeClient.define('user', {
  email: {
    type: Sequelize.STRING,
    allowNull: true,
    unique: false,
  },
  password: {
    type: Sequelize.STRING,
    allowNull: true,
  }
}, {
  classMethods: {
    //queries: function(){},
    mutations: function(Models, ModelTypes, resolver) {
      console.log("Creating custom mutations for model user");
      return {
        myMutationA: {
          type: MyCustomType,
          args: {
            dataA: {
              data: 'dataA',
              type: new GraphQLNonNull(GraphQLString)
            },
            dataB: {
              data: 'dataB',
              type: new GraphQLNonNull(GraphQLString)
            }
          },
          resolve: (obj, {
            name
          }) => {

            console.log("Calling custom mutator with data")
            console.log(name)
            // Here call sequelize using Models in the scope
            let myFirstPromise = new Promise((resolve, reject) => {
              setTimeout(function() {
                resolve("Success!");
              }, 250);
            });

            return myFirstPromise;
          }
        }
      };
    }
  }
});
@Glavin001
Copy link
Owner

Thanks for creating this issue!

I have added a unit test and also added it to the demo:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants