facebook / facebook/relay

[relay-compiler] Compiler doesn't work for connections when types are non-nullable

Open
#1,835 4 comments 5 reactions 0 assignees View on GitHub
bug wontfix
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I'm having an issue with the `relay-compiler` that fails when fields are required.

Here's a simplified version of the schema that I used when I was hitting the issue.

```graphql
allPosts(after: String, before: String, first: Int, last: Int): PostConnection!

type PostConnection {
pageInfo: PageInfo!
edges: [PostEdge]
}

type PostEdge {
node: Post!
cursor: String!
}

type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}

type Post {
id: ID!
title: String!
}
```

Using required fields on the connections caused the compiler to fail with the following error:

```sh
Invariant Violation: RelaySchemaUtils: Expected type `PostConnection!` to be an object or interface type.
```

![image](https://cloud.githubusercontent.com/assets/4058327/26601178/34fac828-457f-11e7-8ffe-d614520dcc93.png)

Using the following schema without required fields works:

```graphql
allPosts(after: String, before: String, first: Int, last: Int): PostConnection

type PostConnection {
pageInfo: PageInfo
edges: [PostEdge]
}

type PostEdge {
node: Post
cursor: String
}

type PageInfo {
hasNextPage: Boolean
hasPreviousPage: Boolean
startCursor: String
endCursor: String
}

type Post {
id: ID!
title: String!
}
```

Feel free to take a look at the [full project](https://github.com/graphcool-examples/react-graphql/tree/master/quickstart-with-relay-modern) (note that the README doesn't yet include instructions about setting up the `relay-compiler`).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.