Socket
Socket
Sign inDemoInstall

graphql-relay

Package Overview
Dependencies
Maintainers
7
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-relay

A library to help construct a graphql-js server supporting react-relay.


Version published
Weekly downloads
170K
decreased by-2.23%
Maintainers
7
Weekly downloads
 
Created

What is graphql-relay?

The graphql-relay package provides a set of tools to help construct a GraphQL server that follows the Relay specification. It includes helper functions to create connections, nodes, and mutations that conform to the Relay standard.

What are graphql-relay's main functionalities?

Node Definitions

This feature allows you to define a global ID scheme for your GraphQL types, making it easier to fetch objects by their global ID. The code sample demonstrates how to set up node definitions for User and Photo types.

const { nodeDefinitions, fromGlobalId } = require('graphql-relay');
const { nodeInterface, nodeField } = nodeDefinitions(
  (globalId) => {
    const { type, id } = fromGlobalId(globalId);
    if (type === 'User') {
      return getUser(id);
    } else if (type === 'Photo') {
      return getPhoto(id);
    }
    return null;
  },
  (obj) => {
    if (obj instanceof User) {
      return userType;
    } else if (obj instanceof Photo) {
      return photoType;
    }
    return null;
  }
);

Connection Definitions

This feature helps in creating connection types that follow the Relay specification. The code sample shows how to create a connection type for User.

const { connectionDefinitions } = require('graphql-relay');
const { connectionType: userConnection } = connectionDefinitions({
  name: 'User',
  nodeType: userType
});

Mutations

This feature allows you to create mutations that follow the Relay specification. The code sample demonstrates how to create an AddUser mutation.

const { mutationWithClientMutationId } = require('graphql-relay');
const { GraphQLString } = require('graphql');
const AddUserMutation = mutationWithClientMutationId({
  name: 'AddUser',
  inputFields: {
    name: { type: GraphQLString }
  },
  outputFields: {
    user: {
      type: userType,
      resolve: (payload) => getUser(payload.userId)
    }
  },
  mutateAndGetPayload: ({ name }) => {
    const userId = addUser(name);
    return { userId };
  }
});

Other packages similar to graphql-relay

FAQs

Package last updated on 31 Mar 2018

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