🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

pothos-plugin-result

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pothos-plugin-result

A Pothos plugin for easily creating GraphQL schemas that reflect the results of specific actions.

2.0.0
latest
npm
Version published
Weekly downloads
206
Maintainers
0
Weekly downloads
 
Created
Source

pothos-plugin-result

A Pothos plugin for easily creating GraphQL schemas that reflect the results of specific actions.

Usage

Install

$ yarn add pothos-plugin-result

Setup

import ResultPlugin from "pothos-plugin-result";

const builder = new SchemaBuilder({
  plugins: [ResultPlugin],
});

Example

builder.mutationType({
  fields: (t) => ({
    createPost: t.result({
      type: {
        createdPost: PostRef,
      },
      args: {
        title: t.arg.string({ required: true }),
      },
      resolve: (_root, { title }) => {
        return {
          createdPost: {
            id: "1",
            title,
          },
        };
      },
    }),

    // @pothos/plugin-with-input plugin required.
    updatePost: t.resultWithInput({
      type: {
        updatedPost: PostRef,
      },
      input: {
        postId: t.input.id({ required: true }),
        title: t.input.string({ required: true }),
      },
      resolve: (_root, { input }) => {
        return {
          updatedPost: {
            id: input.postId.toString(),
            title: input.title,
          },
        };
      },
    }),
  }),
});

You can get the GraphQL schema as output below:

type Mutation {
  createPost(title: String!): MutationCreatePostResult!
  updatePost(input: MutationUpdatePostInput!): MutationUpdatePostResult!
}

type MutationCreatePostResult {
  createdPost: Post
}

input MutationUpdatePostInput {
  postId: ID!
  title: String!
}

type MutationUpdatePostResult {
  updatedPost: Post
}

Limitation

  • Only can be used in mutation type.
  • The types that can be created are limited to objects. Array types are not supported. Fields contained in the type are nullable.

License

MIT

Keywords

pothos

FAQs

Package last updated on 17 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