Skip to content

Commit

Permalink
Graphql TS schema extensions (#6856)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown authored Nov 1, 2021
1 parent 44cbef5 commit f3e8aac
Show file tree
Hide file tree
Showing 28 changed files with 1,293 additions and 685 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-years-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': minor
---

Added `graphql.extend` and `graphql.wrap`.
5 changes: 5 additions & 0 deletions .changeset/quick-bananas-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/auth': major
---

Updated the way the schema extension is added, this may result in schema re-ordering.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ jobs:
'document-field.test.ts',
'default-values.test.ts',
'extend-graphql-schema.test.ts',
'extend-graphql-schema-graphql-ts.test.ts',
'json.test.ts',
'rest-api.test.ts',
'roles.test.ts',
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/docs/guides/virtual-fields.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ This fragment tells the Keystone Admin UI which values to show in the item page
!> This information is specifically for TypeScript users of the `graphql.object()` function with a self-referential GraphQL type.
GraphQL types will often contain references to themselves and to make TypeScript allow that, you need have an explicit type annotation of `graphql.ObjectType<RootVal>` along with making `fields` a function that returns the object.
GraphQL types will often contain references to themselves and to make TypeScript allow that, you need have an explicit type annotation of `graphql.ObjectType<Source>` along with making `fields` a function that returns the object.
```ts
type PersonRootVal = { name: string; friends: PersonRootVal[] };
type PersonSource = { name: string; friends: PersonSource[] };
const Person: graphql.ObjectType<PersonRootVal> = graphql.object<PersonRootVal>()({
const Person: graphql.ObjectType<PersonSource> = graphql.object<PersonSource>()({
name: "Person",
fields: () => ({
name: graphql.field({ type: graphql.String }),
Expand Down
102 changes: 51 additions & 51 deletions examples-staging/auth/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,57 +1,6 @@
# This file is automatically generated by Keystone, do not modify it manually.
# Modify your Keystone config when you want to change this.

input CreateInitialUserInput {
name: String
email: String
password: String
}

type Mutation {
createInitialUser(
data: CreateInitialUserInput!
): UserAuthenticationWithPasswordSuccess!
authenticateUserWithPassword(
email: String!
password: String!
): UserAuthenticationWithPasswordResult!
createUser(data: UserCreateInput!): User
createUsers(data: [UserCreateInput!]!): [User]
updateUser(where: UserWhereUniqueInput!, data: UserUpdateInput!): User
updateUsers(data: [UserUpdateArgs!]!): [User]
deleteUser(where: UserWhereUniqueInput!): User
deleteUsers(where: [UserWhereUniqueInput!]!): [User]
endSession: Boolean!
}

union AuthenticatedItem = User

type Query {
authenticatedItem: AuthenticatedItem
users(
where: UserWhereInput! = {}
orderBy: [UserOrderByInput!]! = []
take: Int
skip: Int! = 0
): [User!]
user(where: UserWhereUniqueInput!): User
usersCount(where: UserWhereInput! = {}): Int
keystone: KeystoneMeta!
}

union UserAuthenticationWithPasswordResult =
UserAuthenticationWithPasswordSuccess
| UserAuthenticationWithPasswordFailure

type UserAuthenticationWithPasswordSuccess {
sessionToken: String!
item: User!
}

type UserAuthenticationWithPasswordFailure {
message: String!
}

type User {
id: ID!
name: String
Expand Down Expand Up @@ -167,6 +116,57 @@ scalar JSON
url: "http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf"
)

type Mutation {
createUser(data: UserCreateInput!): User
createUsers(data: [UserCreateInput!]!): [User]
updateUser(where: UserWhereUniqueInput!, data: UserUpdateInput!): User
updateUsers(data: [UserUpdateArgs!]!): [User]
deleteUser(where: UserWhereUniqueInput!): User
deleteUsers(where: [UserWhereUniqueInput!]!): [User]
endSession: Boolean!
authenticateUserWithPassword(
email: String!
password: String!
): UserAuthenticationWithPasswordResult
createInitialUser(
data: CreateInitialUserInput!
): UserAuthenticationWithPasswordSuccess!
}

union UserAuthenticationWithPasswordResult =
UserAuthenticationWithPasswordSuccess
| UserAuthenticationWithPasswordFailure

type UserAuthenticationWithPasswordSuccess {
sessionToken: String!
item: User!
}

type UserAuthenticationWithPasswordFailure {
message: String!
}

input CreateInitialUserInput {
name: String
email: String
password: String
}

type Query {
users(
where: UserWhereInput! = {}
orderBy: [UserOrderByInput!]! = []
take: Int
skip: Int! = 0
): [User!]
user(where: UserWhereUniqueInput!): User
usersCount(where: UserWhereInput! = {}): Int
keystone: KeystoneMeta!
authenticatedItem: AuthenticatedItem
}

union AuthenticatedItem = User

type KeystoneMeta {
adminMeta: KeystoneAdminMeta!
}
Expand Down
58 changes: 29 additions & 29 deletions examples-staging/basic/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

type Query {
randomNumber: RandomNumber
authenticatedItem: AuthenticatedItem
users(
where: UserWhereInput! = {}
orderBy: [UserOrderByInput!]! = []
Expand All @@ -29,6 +28,7 @@ type Query {
post(where: PostWhereUniqueInput!): Post
postsCount(where: PostWhereInput! = {}): Int
keystone: KeystoneMeta!
authenticatedItem: AuthenticatedItem
}

type RandomNumber {
Expand All @@ -38,13 +38,6 @@ type RandomNumber {

type Mutation {
createRandomPosts: [Post!]!
createInitialUser(
data: CreateInitialUserInput!
): UserAuthenticationWithPasswordSuccess!
authenticateUserWithPassword(
email: String!
password: String!
): UserAuthenticationWithPasswordResult!
createUser(data: UserCreateInput!): User
createUsers(data: [UserCreateInput!]!): [User]
updateUser(where: UserWhereUniqueInput!, data: UserUpdateInput!): User
Expand All @@ -67,27 +60,13 @@ type Mutation {
deletePost(where: PostWhereUniqueInput!): Post
deletePosts(where: [PostWhereUniqueInput!]!): [Post]
endSession: Boolean!
}

input CreateInitialUserInput {
name: String
email: String
password: String
}

union AuthenticatedItem = User

union UserAuthenticationWithPasswordResult =
UserAuthenticationWithPasswordSuccess
| UserAuthenticationWithPasswordFailure

type UserAuthenticationWithPasswordSuccess {
sessionToken: String!
item: User!
}

type UserAuthenticationWithPasswordFailure {
message: String!
authenticateUserWithPassword(
email: String!
password: String!
): UserAuthenticationWithPasswordResult
createInitialUser(
data: CreateInitialUserInput!
): UserAuthenticationWithPasswordSuccess!
}

type User {
Expand Down Expand Up @@ -500,6 +479,27 @@ scalar JSON
url: "http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf"
)

union UserAuthenticationWithPasswordResult =
UserAuthenticationWithPasswordSuccess
| UserAuthenticationWithPasswordFailure

type UserAuthenticationWithPasswordSuccess {
sessionToken: String!
item: User!
}

type UserAuthenticationWithPasswordFailure {
message: String!
}

input CreateInitialUserInput {
name: String
email: String
password: String
}

union AuthenticatedItem = User

type KeystoneMeta {
adminMeta: KeystoneAdminMeta!
}
Expand Down
Loading

0 comments on commit f3e8aac

Please sign in to comment.