Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-mutate

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-mutate

GraphQL nested mutation

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

graphql-mutate

Make GraphQL support nested mutations

Goal

Schema

type User {
  id: ID
  name: String
  articleCount: Int
  team: Team
  update(input: UserInput): String
  addArticle(input: ArticleInput): Article
}

update and addArticle is mutation in type User

query {
  user(id: 1) {
    id
    name
    articleCount
    team
    update(input: { name: "Justin" })
    addArticle(input: { title: "Hello"}) {
      title
    }
  }
}

We hope it first executes update and then addArticle sequentially.
After executing mutations, it will evaluate name and articleCount in parallel because update and addArticle may change value of name or articleCount.
But it can still evaluate id and team immediately before executing mutations because they won't change by mutations.

How

Use graphql-mutate!

npm install graphql-mutate
const { mutate } = require('graphql-mutate')
const { makeExecutableSchema } = require('graphql-tools')

const User = require('./User') // User type resolvers

const resolvers = {
  Query: {},
  Mutation: {},
  User: mutate(User, {
    mutations: ['update', 'addArticle'],
    dependencies: ['name', 'articleCount'],
  })
}

const schema = makeExecutableSchema({
  typeDefs,
  resolvers,
})

const User = require('./User') is normal type resolver, and you just wrap it with mutate.

  • mutations option: a array includes all mutation field names
  • dependencies option: a array includes all field names that may be affected by mutations

Example

See doc

TODO

[ ] Testing

License

graphql-mutate is available under the MIT license.

Keywords

FAQs

Package last updated on 25 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc