nexus/tests/plugins/__snapshots__/connectionPlugin.spec.ts.snap

729 lines
20 KiB
Plaintext
Raw Permalink Normal View History

// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`basic behavior can define custom resolve 1`] = `
Object {
"data": Object {
"users": Object {
"edges": Array [
Object {
"cursor": "YXJyYXljb25uZWN0aW9uOjA=",
"node": Object {
"id": "User:1",
},
},
Object {
"cursor": "YXJyYXljb25uZWN0aW9uOjE=",
"node": Object {
"id": "User:2",
},
},
],
"pageInfo": Object {
"endCursor": "YXJyYXljb25uZWN0aW9uOjE=",
"hasNextPage": true,
"hasPreviousPage": false,
"startCursor": "YXJyYXljb25uZWN0aW9uOjA=",
},
},
},
}
`;
exports[`basic behavior can define custom resolve, supplying nodes directly 1`] = `
Object {
"data": Object {
"users": Object {
"edges": Array [
Object {
"cursor": "YXJyYXljb25uZWN0aW9uOjA=",
"node": Object {
"id": "User:1",
},
},
Object {
"cursor": "YXJyYXljb25uZWN0aW9uOjE=",
"node": Object {
"id": "User:2",
},
},
],
"nodes": Array [
Object {
"id": "User:1",
},
Object {
"id": "User:2",
},
],
"pageInfo": Object {
"endCursor": "YXJyYXljb25uZWN0aW9uOjE=",
"hasNextPage": true,
"hasPreviousPage": false,
"startCursor": "YXJyYXljb25uZWN0aW9uOjA=",
},
},
},
}
`;
exports[`basic behavior can define custom resolve, which will derive nodes if includeNodesField is true 1`] = `
Object {
"data": Object {
"users": Object {
"edges": Array [
Object {
"cursor": "YXJyYXljb25uZWN0aW9uOjA=",
"node": Object {
"id": "User:1",
},
},
Object {
"cursor": "YXJyYXljb25uZWN0aW9uOjE=",
"node": Object {
"id": "User:2",
},
},
],
"nodes": Array [
Object {
"id": "User:1",
},
Object {
"id": "User:2",
},
],
"pageInfo": Object {
"endCursor": "YXJyYXljb25uZWN0aW9uOjE=",
"hasNextPage": true,
"hasPreviousPage": false,
"startCursor": "YXJyYXljb25uZWN0aW9uOjA=",
},
},
},
}
`;
exports[`basic behavior resolves any promises in nodes 1`] = `
Object {
"data": Object {
"users": Object {
"edges": Array [
Object {
"cursor": "Y3Vyc29yOjA=",
"node": Object {
"id": "User:1",
},
},
Object {
"cursor": "Y3Vyc29yOjE=",
"node": Object {
"id": "User:2",
},
},
Object {
"cursor": "Y3Vyc29yOjI=",
"node": Object {
"id": "User:3",
},
},
Object {
"cursor": "Y3Vyc29yOjM=",
"node": Object {
"id": "User:4",
},
},
Object {
"cursor": "Y3Vyc29yOjQ=",
"node": Object {
"id": "User:5",
},
},
Object {
"cursor": "Y3Vyc29yOjU=",
"node": Object {
"id": "User:6",
},
},
Object {
"cursor": "Y3Vyc29yOjY=",
"node": Object {
"id": "User:7",
},
},
Object {
"cursor": "Y3Vyc29yOjc=",
"node": Object {
"id": "User:8",
},
},
Object {
"cursor": "Y3Vyc29yOjg=",
"node": Object {
"id": "User:9",
},
},
Object {
"cursor": "Y3Vyc29yOjk=",
"node": Object {
"id": "User:10",
},
},
],
"pageInfo": Object {
"endCursor": "Y3Vyc29yOjk=",
"hasNextPage": false,
"hasPreviousPage": false,
"startCursor": "Y3Vyc29yOjA=",
},
},
},
}
`;
exports[`basic behavior should adhere to the Relay spec 1`] = `
"type UserConnection {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Edge-Types\\"\\"\\"
edges: [UserEdge]
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo\\"\\"\\"
pageInfo: PageInfo!
}"
`;
exports[`basic behavior should adhere to the Relay spec 2`] = `
"type UserEdge {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Cursor\\"\\"\\"
cursor: String!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Node\\"\\"\\"
node: User
}"
`;
exports[`basic behavior should adhere to the Relay spec 3`] = `
"\\"\\"\\"
PageInfo cursor, as defined in https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo
\\"\\"\\"
type PageInfo {
\\"\\"\\"
Used to indicate whether more edges exist following the set defined by the clients arguments.
\\"\\"\\"
hasNextPage: Boolean!
\\"\\"\\"
Used to indicate whether more edges exist prior to the set defined by the clients arguments.
\\"\\"\\"
hasPreviousPage: Boolean!
\\"\\"\\"
The cursor corresponding to the first nodes in edges. Null if the connection is empty.
\\"\\"\\"
startCursor: String
\\"\\"\\"
The cursor corresponding to the last nodes in edges. Null if the connection is empty.
\\"\\"\\"
endCursor: String
}"
`;
exports[`field level configuration #515 - custom non-string cursor type 1`] = `
2020-11-28 03:22:48 +08:00
"\\"\\"\\"
PageInfo cursor, as defined in https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo
2020-11-28 03:22:48 +08:00
\\"\\"\\"
type PageInfo {
\\"\\"\\"
The cursor corresponding to the last nodes in edges. Null if the connection is empty.
\\"\\"\\"
endCursor: String
2020-11-28 03:22:48 +08:00
\\"\\"\\"
Used to indicate whether more edges exist following the set defined by the clients arguments.
\\"\\"\\"
hasNextPage: Boolean!
2020-11-28 03:22:48 +08:00
\\"\\"\\"
Used to indicate whether more edges exist prior to the set defined by the clients arguments.
\\"\\"\\"
hasPreviousPage: Boolean!
2020-11-28 03:22:48 +08:00
\\"\\"\\"
The cursor corresponding to the first nodes in edges. Null if the connection is empty.
\\"\\"\\"
startCursor: String
}
type Query {
fieldLevel(
\\"\\"\\"Returns the elements in the list that come after the specified cursor\\"\\"\\"
after: String
\\"\\"\\"Returns the elements in the list that come before the specified cursor\\"\\"\\"
before: String
2020-11-28 03:22:48 +08:00
\\"\\"\\"Returns the first n elements from the list.\\"\\"\\"
first: Int
\\"\\"\\"Returns the last n elements from the list.\\"\\"\\"
last: Int
2020-11-28 03:22:48 +08:00
): QueryFieldLevel_Connection!
fieldLevel2(
\\"\\"\\"Returns the elements in the list that come after the specified cursor\\"\\"\\"
after: String
\\"\\"\\"Returns the elements in the list that come before the specified cursor\\"\\"\\"
before: String
2020-11-28 03:22:48 +08:00
\\"\\"\\"Returns the first n elements from the list.\\"\\"\\"
first: Int
\\"\\"\\"Returns the last n elements from the list.\\"\\"\\"
last: Int
2020-11-28 03:22:48 +08:00
): QueryFieldLevel2_Connection!
pluginLevel(
\\"\\"\\"Returns the elements in the list that come after the specified cursor\\"\\"\\"
after: String
\\"\\"\\"Returns the elements in the list that come before the specified cursor\\"\\"\\"
before: String
2020-11-28 03:22:48 +08:00
\\"\\"\\"Returns the first n elements from the list.\\"\\"\\"
first: Int
2020-11-28 03:22:48 +08:00
\\"\\"\\"Returns the last n elements from the list.\\"\\"\\"
last: Int
): UserConnection!
}
2022-02-18 01:47:40 +08:00
type QueryFieldLevel2_Connection {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Edge-Types\\"\\"\\"
2022-02-18 01:47:40 +08:00
edges: [QueryFieldLevel2_Edge!]!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo\\"\\"\\"
pageInfo: PageInfo!
}
2022-02-18 01:47:40 +08:00
type QueryFieldLevel2_Edge {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Cursor\\"\\"\\"
2022-02-18 01:47:40 +08:00
cursor: UUID4!
2020-11-28 03:22:48 +08:00
delta: Int!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Node\\"\\"\\"
node: User!
}
2022-02-18 01:47:40 +08:00
type QueryFieldLevel_Connection {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Edge-Types\\"\\"\\"
2022-02-18 01:47:40 +08:00
edges: [QueryFieldLevel_Edge!]!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo\\"\\"\\"
pageInfo: PageInfo!
}
2022-02-18 01:47:40 +08:00
type QueryFieldLevel_Edge {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Cursor\\"\\"\\"
2022-02-18 01:47:40 +08:00
cursor: UUID!
2020-11-28 03:22:48 +08:00
delta: Int!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Node\\"\\"\\"
node: User!
}
2022-02-18 01:47:40 +08:00
scalar UUID
scalar UUID4
type User {
id: ID!
name: String!
}
type UserConnection {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Edge-Types\\"\\"\\"
edges: [UserEdge!]!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo\\"\\"\\"
pageInfo: PageInfo!
}
type UserEdge {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Cursor\\"\\"\\"
2020-11-28 03:22:48 +08:00
cursor: UUID!
delta: Int!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Node\\"\\"\\"
node: User!
2022-02-18 01:47:40 +08:00
}"
2020-11-28 03:22:48 +08:00
`;
exports[`field level configuration #670 should explicitly state nullability for connectionPlugin args & fields 1`] = `
"\\"\\"\\"
PageInfo cursor, as defined in https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo
\\"\\"\\"
type PageInfo {
2020-11-28 03:22:48 +08:00
\\"\\"\\"
The cursor corresponding to the last nodes in edges. Null if the connection is empty.
\\"\\"\\"
endCursor: String
\\"\\"\\"
Used to indicate whether more edges exist following the set defined by the clients arguments.
\\"\\"\\"
hasNextPage: Boolean!
\\"\\"\\"
Used to indicate whether more edges exist prior to the set defined by the clients arguments.
\\"\\"\\"
hasPreviousPage: Boolean!
\\"\\"\\"
The cursor corresponding to the first nodes in edges. Null if the connection is empty.
\\"\\"\\"
startCursor: String
2020-11-28 03:22:48 +08:00
}
2020-11-28 03:22:48 +08:00
type Query {
users(
\\"\\"\\"Returns the elements in the list that come after the specified cursor\\"\\"\\"
after: String
\\"\\"\\"Returns the elements in the list that come before the specified cursor\\"\\"\\"
before: String
\\"\\"\\"Returns the first n elements from the list.\\"\\"\\"
first: Int
\\"\\"\\"Returns the last n elements from the list.\\"\\"\\"
last: Int
): UserConnection!
}
type User {
id: ID!
name: String!
}
2020-11-28 03:22:48 +08:00
type UserConnection {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Edge-Types\\"\\"\\"
2020-11-28 03:22:48 +08:00
edges: [UserEdge!]!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo\\"\\"\\"
2020-11-28 03:22:48 +08:00
pageInfo: PageInfo!
}
type UserEdge {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Cursor\\"\\"\\"
2020-11-28 03:22:48 +08:00
cursor: String!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Node\\"\\"\\"
2020-11-28 03:22:48 +08:00
node: User!
2022-02-18 01:47:40 +08:00
}"
`;
exports[`field level configuration can configure connection names per-instance 1`] = `"QueryUsersTestFieldConnection"`;
exports[`field level configuration can configure edge names per-instance 1`] = `"QueryUsersTestFieldEdge"`;
exports[`field level configuration can configure the connection per-instance 1`] = `
"type QueryUsers_Connection {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Edge-Types\\"\\"\\"
edges: [UserEdge]
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo\\"\\"\\"
pageInfo: PageInfo!
totalCount: Int
}"
`;
exports[`field level configuration can configure the edge per-instance 1`] = `
"type QueryUsers_Connection {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Edge-Types\\"\\"\\"
edges: [QueryUsers_Edge]
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo\\"\\"\\"
pageInfo: PageInfo!
}"
`;
exports[`field level configuration can configure the edge per-instance 2`] = `
"type QueryUsers_Edge {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Cursor\\"\\"\\"
cursor: String!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Node\\"\\"\\"
node: User
role: String
}"
`;
exports[`field level configuration can define a schema with multiple plugins, and separate them by typePrefix 1`] = `
2020-11-28 03:22:48 +08:00
"type AnalyticsUserConnection {
averageCount: Int
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Edge-Types\\"\\"\\"
2020-11-28 03:22:48 +08:00
edges: [AnalyticsUserEdge]
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo\\"\\"\\"
pageInfo: PageInfo!
2020-11-28 03:22:48 +08:00
totalCount: Int
}
2020-11-28 03:22:48 +08:00
type AnalyticsUserEdge {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Cursor\\"\\"\\"
cursor: String!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Node\\"\\"\\"
node: User
}
\\"\\"\\"
PageInfo cursor, as defined in https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo
\\"\\"\\"
type PageInfo {
2020-11-28 03:22:48 +08:00
\\"\\"\\"
The cursor corresponding to the last nodes in edges. Null if the connection is empty.
\\"\\"\\"
endCursor: String
\\"\\"\\"
Used to indicate whether more edges exist following the set defined by the clients arguments.
\\"\\"\\"
hasNextPage: Boolean!
\\"\\"\\"
Used to indicate whether more edges exist prior to the set defined by the clients arguments.
\\"\\"\\"
hasPreviousPage: Boolean!
\\"\\"\\"
The cursor corresponding to the first nodes in edges. Null if the connection is empty.
\\"\\"\\"
startCursor: String
2020-11-28 03:22:48 +08:00
}
2020-11-28 03:22:48 +08:00
type Query {
2022-02-18 01:47:40 +08:00
userStats(
2020-11-28 03:22:48 +08:00
\\"\\"\\"Returns the elements in the list that come after the specified cursor\\"\\"\\"
after: String
\\"\\"\\"Returns the elements in the list that come before the specified cursor\\"\\"\\"
before: String
\\"\\"\\"Returns the first n elements from the list.\\"\\"\\"
first: Int
\\"\\"\\"Returns the last n elements from the list.\\"\\"\\"
last: Int
2022-02-18 01:47:40 +08:00
): AnalyticsUserConnection
users(
2020-11-28 03:22:48 +08:00
\\"\\"\\"Returns the elements in the list that come after the specified cursor\\"\\"\\"
after: String
\\"\\"\\"Returns the elements in the list that come before the specified cursor\\"\\"\\"
before: String
\\"\\"\\"Returns the first n elements from the list.\\"\\"\\"
first: Int
\\"\\"\\"Returns the last n elements from the list.\\"\\"\\"
last: Int
2022-02-18 01:47:40 +08:00
): UserConnection
}
2020-11-28 03:22:48 +08:00
type User {
id: ID
name: String
}
type UserConnection {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Edge-Types\\"\\"\\"
2020-11-28 03:22:48 +08:00
edges: [UserEdge]
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo\\"\\"\\"
pageInfo: PageInfo!
}
2020-11-28 03:22:48 +08:00
type UserEdge {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Cursor\\"\\"\\"
cursor: String!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Node\\"\\"\\"
node: User
2022-02-18 01:47:40 +08:00
}"
`;
exports[`field level configuration can define additional args for the connection 1`] = `
"type Query {
users(
\\"\\"\\"This should be included\\"\\"\\"
filter: String
\\"\\"\\"Returns the first n elements from the list.\\"\\"\\"
first: Int
\\"\\"\\"Returns the elements in the list that come after the specified cursor\\"\\"\\"
after: String
\\"\\"\\"Returns the last n elements from the list.\\"\\"\\"
last: Int
\\"\\"\\"Returns the elements in the list that come before the specified cursor\\"\\"\\"
before: String
): UserConnection
ok(ok: Boolean): Boolean
}"
`;
exports[`field level configuration can inherit the additional args from the main config 1`] = `
"type Query {
users(
\\"\\"\\"This should be included\\"\\"\\"
order: String!
\\"\\"\\"This should also be included\\"\\"\\"
filter: String
\\"\\"\\"Returns the first n elements from the list.\\"\\"\\"
first: Int
\\"\\"\\"Returns the elements in the list that come after the specified cursor\\"\\"\\"
after: String
\\"\\"\\"Returns the last n elements from the list.\\"\\"\\"
last: Int
\\"\\"\\"Returns the elements in the list that come before the specified cursor\\"\\"\\"
before: String
): UserConnection
ok(ok: Boolean): Boolean
}"
`;
exports[`field level configuration prints the types associated with the connection plugin correctly 1`] = `
"
/**
* Adds a Relay-style connection to the type, with numerous options for configuration
*
* @see https://nexusjs.org/docs/plugins/connection
*/
connectionField<FieldName extends string>(
fieldName: FieldName,
config: connectionPluginCore.ConnectionFieldConfig<TypeName, FieldName>
): void
"
`;
exports[`global plugin configuration allows disabling backward pagination 1`] = `
"type Query {
users(
\\"\\"\\"Returns the first n elements from the list.\\"\\"\\"
first: Int!
\\"\\"\\"Returns the elements in the list that come after the specified cursor\\"\\"\\"
after: String
): UserConnection
ok(ok: Boolean): Boolean
}"
`;
exports[`global plugin configuration allows disabling backward pagination w/ strictArgs: false to make \`first\` nullable 1`] = `
"type Query {
users(
\\"\\"\\"Returns the first n elements from the list.\\"\\"\\"
first: Int
\\"\\"\\"Returns the elements in the list that come after the specified cursor\\"\\"\\"
after: String
): UserConnection
ok(ok: Boolean): Boolean
}"
`;
exports[`global plugin configuration allows disabling forward pagination 1`] = `
"type Query {
users(
\\"\\"\\"Returns the last n elements from the list.\\"\\"\\"
last: Int!
\\"\\"\\"Returns the elements in the list that come before the specified cursor\\"\\"\\"
before: String
): UserConnection
ok(ok: Boolean): Boolean
}"
`;
exports[`global plugin configuration allows disabling forward pagination w/ strictArgs:false to make \`last\` nullable 1`] = `
"type Query {
users(
\\"\\"\\"Returns the last n elements from the list.\\"\\"\\"
last: Int
\\"\\"\\"Returns the elements in the list that come before the specified cursor\\"\\"\\"
before: String
): UserConnection
ok(ok: Boolean): Boolean
}"
`;
exports[`global plugin configuration can configure additional fields for the connection globally 1`] = `
"type UserConnection {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Edge-Types\\"\\"\\"
edges: [UserEdge]
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo\\"\\"\\"
pageInfo: PageInfo!
totalCount: Int
}"
`;
exports[`global plugin configuration can configure additional fields for the edge globally 1`] = `
"type UserEdge {
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Cursor\\"\\"\\"
cursor: String!
\\"\\"\\"https://relay.dev/graphql/connections.htm#sec-Node\\"\\"\\"
node: User
createdAt: String
}"
`;
exports[`global plugin configuration can configure connection names globally 1`] = `"QueryUsersTestGlobalConnection"`;
exports[`global plugin configuration can configure edge names globally 1`] = `"QueryUsersTestGlobalEdge"`;
exports[`global plugin configuration can define additional args for all connections 1`] = `
"type Query {
users(
\\"\\"\\"This should be included\\"\\"\\"
order: String!
\\"\\"\\"Returns the first n elements from the list.\\"\\"\\"
first: Int
\\"\\"\\"Returns the elements in the list that come after the specified cursor\\"\\"\\"
after: String
\\"\\"\\"Returns the last n elements from the list.\\"\\"\\"
last: Int
\\"\\"\\"Returns the elements in the list that come before the specified cursor\\"\\"\\"
before: String
): UserConnection
ok(ok: Boolean): Boolean
}"
`;
exports[`global plugin configuration can include a "nodes" field, with an array of nodes 1`] = `"UserConnection"`;
exports[`global plugin configuration logs error if the extendConnection resolver is not specified 1`] = `
Array [
[Error: Nexus Connection Plugin: Missing totalCount resolver property for Query.users. Set requireResolver to "false" on the field config if you do not need a resolver.],
]
`;
exports[`global plugin configuration logs error if the extendEdge resolver is not specified 1`] = `
Array [
[Error: Nexus Connection Plugin: Missing edgeFields.totalCount resolver property for Query.users. Set requireResolver to "false" on the edge field config if you do not need a resolver.],
]
`;