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

graphql-relay

Package Overview
Dependencies
Maintainers
8
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.

  • 0.10.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
8
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

Keywords

FAQs

Package last updated on 11 Jul 2024

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