简体   繁体   English

React GraphQL Relay - 如何做一个简单的查询?

[英]React GraphQL Relay - How to do a simple query?

The Goal:目标:

I'm trying to query a specific character from a GraphQL server with relay.我正在尝试使用中继从GraphQL 服务器查询特定字符。

The Problem:问题:

The query works in GraphiQL.查询在GraphiQL 中工作。 But here, when running "relay-compiler": "^1.4.1" I'm getting...但是在这里,当运行"relay-compiler": "^1.4.1"我得到...

ERROR: Parse error: Error: FindGraphQLTags: Operation names in graphql tags must be prefixed with the module name and end in "Mutation", "Query", or "Subscription".错误:解析错误:错误:FindGraphQLTags:graphql 标签中的操作名称必须以模块名称为前缀,并以“Mutation”、“Query”或“Subscription”结尾。 Got clientQuery in module Jedi .Jedi模块中获得了clientQuery in "components/Jedi.js"在“组件/Jedi.js”中

The Question:问题:

Can't I just query that specific character like in GraphiQL ?我不能像在 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
          }
        }
    `
})

Operation names in graphql tags must be prefixed with the module name graphql 标签中的操作名称必须以模块名称为前缀

You should rename your query (clientQuery) to BlogPostPreviewQuery if BlogPostPreview is the name of your module.如果 BlogPostPreview 是您的模块的名称,您应该将您的查询 (clientQuery) 重命名为 BlogPostPreviewQuery。

Here are examples.以下是示例。 If query is in:如果查询在:

  • /app/foo.js - fooQuery or fooAnythingQuery /app/foo.js - fooQueryfooAnythingQuery
  • /app/foo/index.js - fooQuery or fooAnythingQuery /app/foo/index.js - fooQueryfooAnythingQuery
  • /app/Foo/index.js - FooQuery or FooAnythingQuery /app/Foo/index.js - FooQueryFooAnythingQuery
  • /app/foo/bar.js - barQuery or barAnythingQuery /app/foo/bar.js - barQuerybarAnythingQuery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM