简体   繁体   中英

Is there way to use Relay without GraphQL?

I'm trying Relay in my React application, and it uses GraphQL by default. It looks like this ( Score is some React.js component):

Score = Relay.createContainer(Score, {
    fragments: {
        score: () => Relay.QL`
            fragment on Score {
                initials,
                score,
            }
        `,
    },
});

The question is: can I use custom API functions to return data into fragments? Like this:

Score = Relay.createContainer(Score, {
    fragments: {
        score: myCustomFunction(), // It will return a dataset.
    },
});

No, not yet. Support for augmenting the server schema with "local" data is being discussed in this GitHub issue .

In the meantime, you have two options:

  • Locate the score computation on the GraphQL server and access it via the schema like you would any other field (note that fields in the schema can be the product of arbitrary computations, so you can do "computed fields" and are not limited to vanilla data-fetching from a secondary store).
  • Locate the data on the client and access it via a side channel apart from GraphQL; for example, you could place it in a Flux store and or some other secondary module.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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