-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support functional resolvers via GQLExtendType
- Loading branch information
1 parent
41f2e30
commit 7605a7e
Showing
40 changed files
with
1,077 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# How Grats Compares to Other Tools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import express from "express"; | ||
import { graphqlHTTP } from "express-graphql"; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
// FIXME: Not supported yet | ||
/** @GQLType */ | ||
type User = { | ||
/** @GQLField */ | ||
email: string; | ||
/** @GQLField */ | ||
name?: string; | ||
}; | ||
|
||
/** @GQLType */ | ||
class Query { | ||
allUsers(): Promise<User[]> { | ||
return prisma.user.findMany(); | ||
} | ||
} | ||
|
||
const schema = makeSchema({ | ||
types: [User, Query], | ||
}); | ||
|
||
const app = express(); | ||
app.use( | ||
"/graphql", | ||
graphqlHTTP({ | ||
schema, | ||
}), | ||
); | ||
|
||
app.listen(4000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import { queryType, objectType, makeSchema } from "@nexus/schema"; | ||
import express from "express"; | ||
import { graphqlHTTP } from "express-graphql"; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
const User = objectType({ | ||
name: "User", | ||
definition(t) { | ||
t.string("email"); | ||
t.string("name", { nullable: true }); | ||
}, | ||
}); | ||
|
||
const Query = queryType({ | ||
definition(t) { | ||
t.list.field("allUsers", { | ||
type: "User", | ||
resolve: () => prisma.user.findMany(), | ||
}); | ||
}, | ||
}); | ||
|
||
const schema = makeSchema({ | ||
types: [User, Query], | ||
}); | ||
|
||
const app = express(); | ||
app.use( | ||
"/graphql", | ||
graphqlHTTP({ | ||
schema, | ||
}), | ||
); | ||
|
||
app.listen(4000); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import express from "express"; | ||
import { graphqlHTTP } from "express-graphql"; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
/** @GQLType */ | ||
export class User { | ||
/** @GQLField */ | ||
email: string; | ||
|
||
/** @GQLField */ | ||
name?: string | null; | ||
} | ||
|
||
/** @GQLType */ | ||
export class Query { | ||
/** @GQLField */ | ||
async allUsers() { | ||
return prisma.user.findMany(); | ||
} | ||
} | ||
|
||
const schema = buildSchemaSync({ | ||
resolvers: [PostResolver, UserResolver], | ||
}); | ||
|
||
const app = express(); | ||
app.use( | ||
"/graphql", | ||
graphqlHTTP({ | ||
schema, | ||
}), | ||
); | ||
app.listen(4000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import { ObjectType, Field, ID, buildSchemaSync } from "type-graphql"; | ||
import express from "express"; | ||
import { graphqlHTTP } from "express-graphql"; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
@ObjectType() | ||
export class User { | ||
@Field() | ||
email: string; | ||
|
||
@Field((type) => String, { nullable: true }) | ||
name?: string | null; | ||
} | ||
|
||
@Resolver(User) | ||
export class UserResolver { | ||
@Query((returns) => [User], { nullable: true }) | ||
async allUsers() { | ||
return prisma.user.findMany(); | ||
} | ||
} | ||
|
||
const schema = buildSchemaSync({ | ||
resolvers: [PostResolver, UserResolver], | ||
}); | ||
|
||
const app = express(); | ||
app.use( | ||
"/graphql", | ||
graphqlHTTP({ | ||
schema, | ||
}), | ||
); | ||
app.listen(4000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## TypeGraphQL + Prisma | ||
|
||
```diff | ||
2d1 | ||
< import { ObjectType, Field, ID, buildSchemaSync } from "type-graphql"; | ||
8c7 | ||
< @ObjectType() | ||
--- | ||
> /** @GQLType */ | ||
10c9 | ||
< @Field() | ||
--- | ||
> /** @GQLField */ | ||
13c12 | ||
< @Field((type) => String, { nullable: true }) | ||
--- | ||
> /** @GQLField */ | ||
17,19c16,18 | ||
< @Resolver(User) | ||
< export class UserResolver { | ||
< @Query((returns) => [User], { nullable: true }) | ||
--- | ||
> /** @GQLType */ | ||
> export class Query { | ||
> /** @GQLField */ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.