Skip to content

Commit

Permalink
connection-test: add that checks generated types
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed May 30, 2021
1 parent 76b6bc5 commit 983d506
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/connection/__tests__/connection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {
GraphQLSchema,
GraphQLString,
graphqlSync,
printSchema,
} from 'graphql';

import { dedent } from '../../__testUtils__/dedent';

import { connectionFromArray } from '../arrayConnection';

import {
Expand Down Expand Up @@ -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!
}
`);
});
});

0 comments on commit 983d506

Please sign in to comment.