Skip to content

Commit

Permalink
Merge pull request join-monster#282 from cliedeman/unwrap-relay-conne…
Browse files Browse the repository at this point in the history
…ction-node

Allow relay connection node type to be Non Null
  • Loading branch information
Andy authored Jul 5, 2018
2 parents 93446c5 + 9ba6369 commit 4d2f1f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/query-ast-to-sql-ast/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export function populateASTNode(queryASTNode, parentTypeNode, sqlASTNode, namesp
// grab the types and fields inside the connection
const stripped = stripRelayConnection(gqlType, queryASTNode, this.fragments)
// reassign those
gqlType = stripped.gqlType
gqlType = stripNonNullType(stripped.gqlType)
queryASTNode = stripped.queryASTNode
// we'll set a flag for pagination.
if (field.sqlPaginate) {
Expand Down Expand Up @@ -540,7 +540,8 @@ function handleColumnsRequiredForPagination(sqlASTNode, namespace) {
// if its a connection type, we need to look up the Node type inside their to find the relevant SQL info
function stripRelayConnection(gqlType, queryASTNode, fragments) {
// get the GraphQL Type inside the list of edges inside the Node from the schema definition
const strippedType = gqlType._fields.edges.type.ofType._fields.node.type
const edgeType = stripNonNullType(gqlType._fields.edges.type)
const strippedType = stripNonNullType(stripNonNullType(edgeType.ofType)._fields.node.type)
// let's remember those arguments on the connection
const args = queryASTNode.arguments
// and then find the fields being selected on the underlying type, also buried within edges and Node
Expand Down
3 changes: 2 additions & 1 deletion test-api/schema-paginated/User.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
GraphQLObjectType,
GraphQLNonNull,
GraphQLList,
GraphQLString,
GraphQLInt,
Expand Down Expand Up @@ -333,7 +334,7 @@ const User = new GraphQLObjectType({
})
})

const connectionConfig = { nodeType: User }
const connectionConfig = { nodeType: GraphQLNonNull(User) }
if (PAGINATE === 'offset') {
connectionConfig.connectionFields = {
total: { type: GraphQLInt }
Expand Down

0 comments on commit 4d2f1f7

Please sign in to comment.