From 983d50671805f229f228f12af8e9cd397806accd Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sun, 30 May 2021 16:27:20 +0300 Subject: [PATCH] connection-test: add that checks generated types --- src/connection/__tests__/connection-test.js | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/connection/__tests__/connection-test.js b/src/connection/__tests__/connection-test.js index 5230ec5..5642f64 100644 --- a/src/connection/__tests__/connection-test.js +++ b/src/connection/__tests__/connection-test.js @@ -6,8 +6,11 @@ import { GraphQLSchema, GraphQLString, graphqlSync, + printSchema, } from 'graphql'; +import { dedent } from '../../__testUtils__/dedent'; + import { connectionFromArray } from '../arrayConnection'; import { @@ -176,4 +179,73 @@ describe('connectionDefinition()', () => { }, }); }); + + it('generates correct types', () => { + // FIXME remove trimEnd after we update to `graphql@16.0.0` + expect(printSchema(schema).trimEnd()).to.deep.equal(dedent` + type Query { + user: User + } + + type User { + name: String + friends(after: String, first: Int, before: String, last: Int): FriendConnection + friendsForward(after: String, first: Int): UserConnection + friendsBackward(before: String, last: Int): UserConnection + } + + """A connection to a list of items.""" + type FriendConnection { + """Information to aid in pagination.""" + pageInfo: PageInfo! + + """A list of edges.""" + edges: [FriendEdge] + totalCount: Int + } + + """Information about pagination in a connection.""" + type PageInfo { + """When paginating forwards, are there more items?""" + hasNextPage: Boolean! + + """When paginating backwards, are there more items?""" + hasPreviousPage: Boolean! + + """When paginating backwards, the cursor to continue.""" + startCursor: String + + """When paginating forwards, the cursor to continue.""" + endCursor: String + } + + """An edge in a connection.""" + type FriendEdge { + """The item at the end of the edge""" + node: User + + """A cursor for use in pagination""" + cursor: String! + friendshipTime: String + } + + """A connection to a list of items.""" + type UserConnection { + """Information to aid in pagination.""" + pageInfo: PageInfo! + + """A list of edges.""" + edges: [UserEdge] + } + + """An edge in a connection.""" + type UserEdge { + """The item at the end of the edge""" + node: User + + """A cursor for use in pagination""" + cursor: String! + } + `); + }); });