How to use the graphql-relay.fromGlobalId 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 renanmav / relayable / packages / server / src / modules / question / mutation / DeleteQuestion.ts View on Github external
mutateAndGetPayload: async (data, { user }: GraphQLContext) => {
    if (!user) return { error: 'You must be authenticated' }

    const { id } = fromGlobalId(data.id)

    const question = await QuestionModel.findById(id)
    if (!question) return { error: "Question doesn't exists" }

    // eslint-disable-next-line eqeqeq
    if (question.author.toString() != user._id) {
      return { error: "You don't own this question" }
    }

    await QuestionModel.findByIdAndDelete(id)

    return { error: null }
  },
  outputFields: {
github logerzhu / simple-graphql / src / build / buildInterfaceContext.js View on Github external
Node: nodeDefinitions((globalId) => {
      const { type, id } = fromGlobalId(globalId)
      console.log('Warning-------------------- node id Fetcher not implement' + type + ' ' + id)
    }, (obj) => {
      const type = obj._fieldType
github ediket / nothinkdb-graphql / src / connection.js View on Github external
export function cursorToPk(cursor) {
  const { id: resourceId } = fromGlobalId(cursorToNodeId(cursor));
  return resourceId;
}
github ironhee / graphql-server-example / server / lib / endpoint.js View on Github external
async (globalId) => {
    const { type: name, id } = fromGlobalId(globalId);
    const endpoint = getEndpoint(name);
    const resource = await endpoint.get(id);
    return resource || null;
  },
  (obj) => {
github bfwg / relay-gallery / schema / schema.js View on Github external
(globalId) => {
    const target = Relay.fromGlobalId(globalId);
    if (target.type === 'Image') {
      return (new myImages()).getById(target.id);
    } else {
      return null;
    }
  },
  (obj) => {
github zth / graphql-client-example-server / src / mutations.ts View on Github external
mutateAndGetPayload: ({ text, completed, id }) => {
    let { type, id: todoItemId } = fromGlobalId(id);
    let targetTodoItem = todoItems.find(t => t.id === parseInt(todoItemId, 10));

    if (!targetTodoItem || type !== "TodoItem") {
      return {
        updatedTodoItem: null
      };
    }

    targetTodoItem.text = text;
    targetTodoItem.completed = completed;

    return {
      updatedTodoItem: targetTodoItem
    };
  }
});
github lXSPandora / Workshop-GraphQL / src / type / QueryType.js View on Github external
resolve: (obj, args, context) => {
        const { id } = fromGlobalId(args.id);
        return UserLoader.load(context, id);
      },
    },