React GraphQL Relay - How to do a simple query?
Asked Answered
B

2

7

The Goal:

I'm trying to query a specific character from a GraphQL server with relay.

The Problem:

The query works in GraphiQL. But here, when running "relay-compiler": "^1.4.1" I'm getting...

ERROR: Parse error: Error: FindGraphQLTags: Operation names in graphql tags must be prefixed with the module name and end in "Mutation", "Query", or "Subscription". Got clientQuery in module Jedi. in "components/Jedi.js"

The Question:

Can't I just query that specific character like in GraphiQL ? How can I achieve this?

The Code:

import React from 'react'
import { QueryRenderer, graphql } from 'react-relay'

const BlogPostPreview = props => {
 return (
   <div key={props.post.id}>{props.post.name}</div>
 )
}

export default QueryRenderer(BlogPostPreview, {
post: graphql`
         query clientQuery {
           character(id: 1000) {
             id
             name
             appearsIn
          }
        }
    `
})
Brilliant answered 24/11, 2017 at 23:9 Comment(0)
C
8

Operation names in graphql tags must be prefixed with the module name

You should rename your query (clientQuery) to BlogPostPreviewQuery if BlogPostPreview is the name of your module.

Coolidge answered 29/11, 2017 at 12:49 Comment(0)
E
5

Here are examples. If query is in:

  • /app/foo.js - fooQuery or fooAnythingQuery
  • /app/foo/index.js - fooQuery or fooAnythingQuery
  • /app/Foo/index.js - FooQuery or FooAnythingQuery
  • /app/foo/bar.js - barQuery or barAnythingQuery
Epicycloid answered 4/2, 2019 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.