How to use the graphql-relay.mutationWithClientMutationId function in graphql-relay

To help you get started, we’ve selected a few graphql-relay examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gaoxiaoliangz / readr / src / server / graphql / mutations / categories.ts View on Github external
import dataProvider from '../../models/dataProvider'
import { checkPermissionsOf } from '../../middleware/requirePermissionsOf'

const cateInputFields = {
  name: {
    type: new GraphQLNonNull(GraphQLString)
  },
  slug: {
    type: new GraphQLNonNull(GraphQLString)
  },
  description: {
    type: GraphQLString
  }
}

export const AddCategoryMutation = mutationWithClientMutationId({
  name: 'AddCategory',
  inputFields: cateInputFields,
  outputFields: {
    _id: {
      type: GraphQLString
    }
  },
  mutateAndGetPayload: async (args, req) => {
    if (req.user.role !== 'admin') {
      return Promise.reject(new Error('Require admin permission!'))
    }
    return dataProvider.Category.utils.save({
      ...args
    }).then(res => {
      return res.toObject()
    })
github bochen2014 / relay-todo-modern / server / data / schema / mutation.js View on Github external
const {
  addTodo,
  changeTodoStatus,
  getTodo,
  getTodos,
  getViewer,
  markAllTodos,
  removeCompletedTodos,
  removeTodo,
  renameTodo,
} = require('../database');
const { GraphQLTodoEdge, GraphQLUser, GraphQLTodo } = require('./types');
const { fromGlobalId_unibet } = require('./unibetIds');

const GraphQLAddTodoMutation = mutationWithClientMutationId({
  name: 'AddTodo',
  inputFields: {
    text: { type: new GraphQLNonNull(GraphQLString) },
  },
  outputFields: {
    todoEdge: {
      type: GraphQLTodoEdge,
      resolve: async ({ localTodoId }) => {
        const todos = await getTodos();
        const todo = todos.find(t => t.id === localTodoId);
        return {
          cursor: cursorForObjectInConnection(todos, todo),
          node: todo,
        };
      },
    },
github jscomplete / learning-graphql-and-relay / schema / main.js View on Github external
const quotesLibrary = { type: QuotesLibraryType };

const queryType = new GraphQLObjectType({
  name: 'RootQuery',
  fields: {
    node: nodeField,
    quotesLibrary: {
      type: QuotesLibraryType,
      description: 'The Quotes Library',
      resolve: () => quotesLibrary
    }
  }
});

const thumbsUpMutation = mutationWithClientMutationId({
  name: 'ThumbsUpMutation',
  inputFields: {
    quoteId: { type: GraphQLString }
  },
  outputFields: {
    quote: {
      type: QuoteType,
      resolve: obj => obj
    }
  },
  mutateAndGetPayload: (params, { db }) => {
    const { id } = fromGlobalId(params.quoteId);
    return Promise.resolve(
      db.collection('quotes').updateOne(
        { _id: ObjectID(id) },
        { $inc: { likesCount: 1 } }
github hung-phan / koa-react-isomorphic / app / server / application / apis / graphql / todos.js View on Github external
};
  },
  interfaces: [nodeInterface]
});

const {
  connectionType: TodoConnection,
  edgeType: GraphQLTodoEdge
} = connectionDefinitions({
  name: "Todo",
  nodeType: TodoType
});

export { TodoConnection, GraphQLTodoEdge };

export const AddTodoMutation = mutationWithClientMutationId({
  name: "AddTodoMutation",
  inputFields: {
    text: { type: new GraphQLNonNull(GraphQLString) }
  },
  outputFields: {
    todoEdge: {
      type: GraphQLTodoEdge,
      async resolve({ todoId }) {
        const [todo, todos] = await Promise.all([
          todosDAO.getById(todoId),
          todosDAO.all()
        ]);

        return {
          cursor: cursorForObjectInConnection(todos, todo),
          node: todo
github relay-tools / found-relay / src / data / schema.js View on Github external
},
  interfaces: [nodeInterface],
});

const GraphQLRoot = new GraphQLObjectType({
  name: 'Root',
  fields: {
    viewer: {
      type: GraphQLUser,
      resolve: getViewer,
    },
    node: nodeField,
  },
});

const GraphQLAddTodoMutation = mutationWithClientMutationId({
  name: 'AddTodo',
  inputFields: {
    text: { type: new GraphQLNonNull(GraphQLString) },
  },
  outputFields: {
    viewer: {
      type: GraphQLUser,
      resolve: getViewer,
    },
    todoEdge: {
      type: GraphQLTodoEdge,
      resolve: ({ todoId }) => {
        const todo = getTodo(todoId);
        return {
          cursor: cursorForObjectInConnection(getTodos(), todo),
          node: todo,
github Svehla / node-graphql-boilerplate / src / gql / models / User / mutations / UpdateUser.ts View on Github external
} from '../../../../constants/index'
import GraphQLUserRole from '../types/GraphQLUserRole'

const PossibleErrors = new GraphQLEnumType({
  name: 'UpdateUserErrors',
  values: {
    USER_IS_NOT_LOGGED: {
      value: USER_IS_NOT_LOGGED,
    },
    USER_NOT_FOUND: {
      value: USER_NOT_FOUND
    }
  },
})

const UpdateUserMutation = mutationWithClientMutationId({
  name: 'UpdateUserMutation',
  description: `this mutation updates a user`,
  inputFields: {
    id: {
      type: new GraphQLNonNull(GraphQLID),
      description: `id of user`
    },
    email: {
      type: GraphQLEmail,
      description: 'email of user'
    },
    name: {
      type: GraphQLString,
      description: 'name of user'
    },
    role: {
github DevelopIntelligenceBoulder / react-flux-blog / blog-post-6 / src / graphql / types / insert-widget-mutation.js View on Github external
'use strict';

import { userType } from './user-type';
import { insertWidgetInputType } from './insert-widget-input-type';
import { WidgetEdge } from '../widget-connection';
import { mutationWithClientMutationId, cursorForObjectInConnection } from 'graphql-relay';
import { insertWidget, getUser, getWidgets } from '../../database';

export const insertWidgetMutation = mutationWithClientMutationId({
	name: 'InsertWidget',
	inputFields: {
		widget: { type: insertWidgetInputType }
	},
	outputFields: {
		user: {
			type: userType,
			resolve: () => getUser(1)
		},
		newWidgetEdge: {
			type: WidgetEdge,
			resolve: widget => ({
				cursor: cursorForObjectInConnection(getWidgets(), widget),
				node: widget })
		}
	},
github artsy / metaphysics / src / schema / v1 / ecommerce / seller_reject_offer_mutation.ts View on Github external
import { graphql } from "graphql"
import { mutationWithClientMutationId } from "graphql-relay"
import { OrderOrFailureUnionType } from "./types/order_or_error_union"
import { SellerOrderFields } from "./query_helpers"
import gql from "lib/gql"
import { extractEcommerceResponse } from "./extractEcommerceResponse"
import { RejectOfferMutationInputType } from "./types/reject_offer_mutation_input_type"
import { ResolverContext } from "types/graphql"

export const SellerRejectOfferMutation = mutationWithClientMutationId<
  any,
  any,
  ResolverContext
>({
  name: "sellerRejectOffer",
  description: "Rejects an offer",
  inputFields: RejectOfferMutationInputType.getFields(),
  outputFields: {
    orderOrError: {
      type: OrderOrFailureUnionType,
    },
  },
  mutateAndGetPayload: ({ offerId, rejectReason }, context) => {
    const { accessToken, exchangeSchema } = context
    if (!accessToken) {
      return new Error("You need to be signed in to perform this action")
github gaoxiaoliangz / readr / src / server / graphql / mutations / categories.ts View on Github external
type: GraphQLString
    }
  },
  mutateAndGetPayload: async (args, req) => {
    if (req.user.role !== 'admin') {
      return Promise.reject(new Error('Require admin permission!'))
    }
    return dataProvider.Category.utils.save({
      ...args
    }).then(res => {
      return res.toObject()
    })
  }
})

export const UpdateCategoryMutation = mutationWithClientMutationId({
  name: 'UpdateCategory',
  inputFields: {
    ...cateInputFields,
    id: {
      type: new GraphQLNonNull(GraphQLID)
    }
  },
  outputFields: {
    ok: {
      type: GraphQLInt
    },
    n: {
      type: GraphQLInt
    },
    nModified: {
      type: GraphQLInt
github artsy / metaphysics / src / schema / v2 / me / consignments / update_submission_mutation.ts View on Github external
authenticity_certificate: authenticityCertificate,
      dimensions_metric: dimensionsMetric,
      edition_number: editionNumber,
      edition_size: editionSize,
      location_city: locationCity,
      location_country: locationCountry,
      location_state: locationState,
      user_id: userID,
      ..._submission,
    }
    if (!submissionUpdateLoader) return null
    return submissionUpdateLoader(submission.id, submission)
  },
}

export default mutationWithClientMutationId(config)