sails.jsgraphqlsails-postgresql

Where to put graphql mutations in Sails?


I've installed npm sails-graphql, but I dont know where to put a mutation, surfing on the web I've found nodejs examples in which they add mutations in index.js but in sails there are no such file. Thanks in advance.


Solution

  • The sails-graphql adapter creates a schema automatically with mutations for all models in /api/models if its specified in the controller:

            // api/controllers/GraphQLController.js
            var graphql = require("graphql");
            var sailsGraphQL = require("sails-graphql");
            ...
            if (!schema) {
            schema = sailsGraphQL.generateSchema(sails.models);
            }
            ...
    

    In this case there is no need to manually add mutations. See https://www.npmjs.com/package/sails-graphql#usage

    Although if you want to edit the generated schema, a better option would be to use a graphql implementation for the required language and load the mutations manually.