facebook / facebook/relay

Relay and Hasura/GraphQL error: no such type exists in the schema

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

Description

I'm trying to fetch data with Relay and GraphQL. Previously, everything is working fine when I only used `App.tsx`, until I creare new `pages/Article` directory and put the three below files:

`Article.tsx`:
```
import React from 'react';
import environment from '@src/environment';
import { graphql, QueryRenderer } from 'react-relay';

import ArticleList from './ArticleList';

const query = graphql`
query ArticleQuery($limit: Int!){
...ArticleList_query
}
`

interface Props {
error: Error | null;
props: any;
}

const renderComponent = ({ error, props }: Props) => {
if(error) {
console.log(error)
return

Error!
;
}
if(!props) {
return
Loading..
;
}
return ;
};

function Article() {
return (

);
}

export default Article;
```

`ArticleList.tsx`:

```
import React from 'react';
import { graphql, createFragmentContainer } from 'react-relay';
import { ArticleList_query } from './__generated__/ArticleList_query.graphql';
import ArticleDetails from './ArticleDetails';

interface Props {
query: ArticleList_query | null;
}

function ArticleList({ query }: Props) {
if(!query) {
return

Error
;
}
const { articles } = query;
if(!articles) {
return
Error
;
}
return (
<>
{
articles.map((article) => article ? (

) : null)
}

);
}

export default createFragmentContainer(
ArticleList,
{
query: graphql`
fragment ArticleList_query on Query {
articles(limit: $limit) {
id
...ArticleDetails_article
}
}
`
}
);
```

`ArticleDetails.tsx`:

```
import React from 'react';
import { graphql, createFragmentContainer } from 'react-relay';
import { ArticleDetails_article } from './__generated__/ArticleDetails_article.graphql';

interface Props {
article: ArticleDetails_article | null;
}

function ArticleDetails({ article }: Props) {
if(!article) {
return


}
const { id, name } = article;
return (
{`${name}`}

);
}

export default createFragmentContainer(
ArticleDetails,
{
article: graphql`
fragment ArticleDetails_article on Article {
id
name
url
updated_at
}
`
}
);
```

`schema.graphql`:
```
type Mutation {
createArticle(name: String!, url: String!): Article
deleteArticle(id: ID!): ID
updateArticle(id: ID!, name: String!, url: String!): Article
}

type Article {
id: ID!
name: String!
author: ArticleAuthor
url: String!
updated_at: String!
}

type ArticleAuthor {
name: String
}

type Query {
articles(limit: Int!): [Article],
article(id: String, name: String): Article
}
```

`package.json`:

```
relay-compiler --src ./src --schema ./data/schema.graphql --language typescript
```

The `Error` which I encountered:
```RelayNetwork: No data returned for operation `ArticleQuery`, got error(s):
no such type exists in the schema: 'Article'```

Now I'm stuck with this error. Did I do anything wrong?
Please help me fix this.

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.