React GraphQL Relay - 如何做一个简单的查询?
React GraphQL Relay - How to do a simple query?
目标:
我正在尝试使用中继从 GraphQL server 中查询特定字符。
问题:
查询在 GraphiQL 中有效。但是在这里,当 运行 "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". Got clientQuery
in module Jedi
. in
"components/Jedi.js"
问题:
我不能像在 GraphiQL 中那样查询特定字符吗?我怎样才能做到这一点?
代码:
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
如果 BlogPostPreview 是您模块的名称,您应该将查询 (clientQuery) 重命名为 BlogPostPreviewQuery。
这里有例子。如果查询在:
/app/foo.js
- fooQuery
或 fooAnythingQuery
/app/foo/index.js
- fooQuery
或 fooAnythingQuery
/app/Foo/index.js
- FooQuery
或 FooAnythingQuery
/app/foo/bar.js
- barQuery
或 barAnythingQuery
目标:
我正在尝试使用中继从 GraphQL server 中查询特定字符。
问题:
查询在 GraphiQL 中有效。但是在这里,当 运行 "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". Got
clientQuery
in moduleJedi
. in "components/Jedi.js"
问题:
我不能像在 GraphiQL 中那样查询特定字符吗?我怎样才能做到这一点?
代码:
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
如果 BlogPostPreview 是您模块的名称,您应该将查询 (clientQuery) 重命名为 BlogPostPreviewQuery。
这里有例子。如果查询在:
/app/foo.js
-fooQuery
或fooAnythingQuery
/app/foo/index.js
-fooQuery
或fooAnythingQuery
/app/Foo/index.js
-FooQuery
或FooAnythingQuery
/app/foo/bar.js
-barQuery
或barAnythingQuery