Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iamchanii/pothos-plugin-result
A Pothos plugin for easily creating GraphQL schemas that reflect the results of specific actions.
https://github.com/iamchanii/pothos-plugin-result
Last synced: 2 months ago
JSON representation
A Pothos plugin for easily creating GraphQL schemas that reflect the results of specific actions.
- Host: GitHub
- URL: https://github.com/iamchanii/pothos-plugin-result
- Owner: iamchanii
- Created: 2024-06-09T08:37:38.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-11T01:05:46.000Z (7 months ago)
- Last Synced: 2024-06-11T13:09:43.577Z (7 months ago)
- Language: TypeScript
- Homepage:
- Size: 121 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```typescript
import ResultPlugin from "pothos-plugin-result";const builder = new SchemaBuilder({
plugins: [ResultPlugin],
});
```### Example
```typescript
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:
```graphql
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