Comparing version 0.0.0-main-33a41869 to 0.0.0-main-3e9a18d4
{ | ||
"name": "grats", | ||
"version": "0.0.0-main-33a41869", | ||
"main": "dist/index.js", | ||
"bin": "dist/cli.js", | ||
"types": "dist/index.d.ts", | ||
"version": "0.0.0-main-3e9a18d4", | ||
"main": "dist/src/index.js", | ||
"bin": "dist/src/cli.js", | ||
"types": "dist/src/index.d.ts", | ||
"license": "MIT", | ||
@@ -31,2 +31,3 @@ "files": [ | ||
}, | ||
"packageManager": "pnpm@8.1.1", | ||
"scripts": { | ||
@@ -33,0 +34,0 @@ "test": "ts-node --esm src/tests/test.ts", |
@@ -22,4 +22,9 @@ # -=[ EXPERIMENTAL PRE ALPHA ]=- | ||
## Example | ||
## Examples | ||
Grats is flexible enough to work with both class-based and functional | ||
approaches to authoring GraphQL types and resolvers. | ||
### Class-Based | ||
```ts | ||
@@ -29,4 +34,4 @@ /** @gqlType */ | ||
/** @gqlField */ | ||
me(): UserResolver { | ||
return new UserResolver(); | ||
me(): User { | ||
return new User(); | ||
} | ||
@@ -37,4 +42,4 @@ /** | ||
*/ | ||
viewer(): UserResolver { | ||
return new UserResolver(); | ||
viewer(): User { | ||
return new User(); | ||
} | ||
@@ -45,5 +50,5 @@ } | ||
* A user in our kick-ass system! | ||
* @gqlType User | ||
* @gqlType | ||
*/ | ||
class UserResolver { | ||
class User { | ||
/** @gqlField */ | ||
@@ -59,4 +64,39 @@ name: string = 'Alice'; | ||
Extracts the following GraphQL schema: | ||
### Functional | ||
```ts | ||
/** @gqlType */ | ||
export type Query {}; | ||
/** @gqlField */ | ||
export function me(_: Query): User { | ||
return { name: "Alice" }; | ||
} | ||
/** | ||
* @gqlField | ||
* @deprecated Please use `me` instead. | ||
*/ | ||
export function viewer(_: Query): User { | ||
return { name: "Alice" }; | ||
} | ||
/** | ||
* A user in our kick-ass system! | ||
* @gqlType | ||
*/ | ||
type User = { | ||
/** @gqlField */ | ||
name: string; | ||
} | ||
/** @gqlField */ | ||
export function greeting(user: User, args: { salutation: string }): string { | ||
return `${args.salutation}, ${user.name}`; | ||
} | ||
``` | ||
Both of the above examples extract the following GraphQL schema: | ||
```graphql | ||
@@ -84,3 +124,3 @@ type Query { | ||
```sh | ||
```bash | ||
npm install express express-graphql grats | ||
@@ -431,5 +471,5 @@ ``` | ||
enum MyEnum { | ||
/** A description of my variant */ | ||
/** A description of my value */ | ||
OK = "OK", | ||
/** A description of my other variant */ | ||
/** A description of my other value */ | ||
ERROR = "ERROR" | ||
@@ -436,0 +476,0 @@ } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
143636
25
2679
577
1