Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Modern:rc.2|3] createFragmentContainer does not allow variable as second argument #1698

Closed
guigrpa opened this issue Apr 27, 2017 · 8 comments

Comments

@guigrpa
Copy link

guigrpa commented Apr 27, 2017

This works:

createFragmentContainer(Component, { /* ... */ });

But this doesn't:

const fragments = {
  /* ... */
};
createFragmentContainer(Component, fragments);

The Relay Compiler complains: FindGraphQLTags: createFragmentContainer expects a second argument of fragment definitions..

In practice, this prevents the definition of fragments at the top of the file, which is where they arguably make more sense.

Not a major issue; keep up the good work!

@leebyron
Copy link
Contributor

Unfortunately this is a known issue - the babel plugin looks for fragments in a particular place.

Could you try not using the wrapping {}?

ie.

const fragments = graphql`
  ...
`;

createFragmentContainer(Component, fragments)

I'm curious if this works out of the box

@guigrpa
Copy link
Author

guigrpa commented Apr 28, 2017

@leebyron Nope, same issue. It also doesn't identify the file causing the problem, btw:

Error: FindGraphQLTags: `createFragmentContainer` expects a second argument of fragment defi
nitions.
    at invariant (D:\Prog\mady\node_modules\relay-compiler\bin\relay-compiler:4714:12)
    at CallExpression (D:\Prog\mady\node_modules\relay-compiler\bin\relay-compiler:4583:82)
    at visit (D:\Prog\mady\node_modules\relay-compiler\bin\relay-compiler:4721:6)
    at traverse (D:\Prog\mady\node_modules\relay-compiler\bin\relay-compiler:4734:8)
    at visit (D:\Prog\mady\node_modules\relay-compiler\bin\relay-compiler:4724:4)
    at D:\Prog\mady\node_modules\relay-compiler\bin\relay-compiler:4738:12
    at Array.forEach (native)
    at traverse (D:\Prog\mady\node_modules\relay-compiler\bin\relay-compiler:4736:13)
    at visit (D:\Prog\mady\node_modules\relay-compiler\bin\relay-compiler:4724:4)
    at D:\Prog\mady\node_modules\relay-compiler\bin\relay-compiler:4738:12

@seanchas
Copy link

@guigrpa you can try this:

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

const fragment = graphql`...`

...

Relay.createFragmentContainer(Component, fragment)

@guigrpa
Copy link
Author

guigrpa commented Apr 28, 2017

@seanchas It worked! Thanks a lot for the workaround

@guigrpa guigrpa closed this as completed Jul 14, 2017
@maikelrobier
Copy link

Could someone explain why this doesn't work:

const fragments = {
  /* ... */
};
createFragmentContainer(Component, fragments);

and this does:

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

const fragment = graphql`...`

...

Relay.createFragmentContainer(Component, fragment)

@seanchas ?

This won't allow to create a HOC around createFragmentContainer. Is that a bug, or there is a special reason for this relay-compiler behavior ?

@maikelrobier
Copy link

I think this is related: #1790

@CoericK
Copy link
Contributor

CoericK commented Jul 6, 2019

Could someone explain why this doesn't work:

const fragments = {
  /* ... */
};
createFragmentContainer(Component, fragments);

and this does:

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

const fragment = graphql`...`

...

Relay.createFragmentContainer(Component, fragment)

@seanchas ?

This won't allow to create a HOC around createFragmentContainer. Is that a bug, or there is a special reason for this relay-compiler behavior ?

Is this working? Im facing the same issue and creating the variable

const fragment = graphql`fragment ......` then createFragmentContainer(MyComponent, fragment) 

still triggers the parse error

@simkessy
Copy link

Was this ever fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants