中继:在Fragment内部使用常量而不是graphql` ...

Arseniy-II

中继createFragmentContainer是有用的功能,易于使用:

const MyComponent = createFragmentContainer(
    MyFragmentComponent,
    {
        job: graphql`
            fragment MyComponent_job on Job {
                id
            }
        `
    }
);

问题是,当查询位于文件末尾时,确实很难读取代码。我更喜欢在导入后将其放在右上角。像这样:

const QUERY_FRAGMENT = graphql`
    fragment MyComponent_job on Job {
        id
    }     
`
// Main code here

const MyComponent = createFragmentContainer(
    MyFragmentComponent,
    {
        job: QUERY_FRAGMENT
    }
);

但是在这种情况下,中继编译器会引发错误: FindGraphQLTags: 'createFragmentContainer' expects fragment definitions to be 'key: graphql'.

有没有一种方法来分离createFragmentContainergraphql

丹尼尔·雷登(Daniel Rearden)

这似乎是的已知问题babel-plugin-relay本期所述,解决方法是更改​​导入:

import Relay, { graphql } from 'react-relay'

const fragment = graphql`...`

...

Relay.createFragmentContainer(Component, fragment)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章