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

TypeError: Cannot read property 'body' of undefined - Fragment in *.graphql file does't load #64

Closed
fokot opened this issue Mar 21, 2017 · 4 comments
Labels

Comments

@fokot
Copy link

fokot commented Mar 21, 2017

You can take a look on example here fokot/GitHunt-React@962e568

import PostedByFragmentFromFile from './PostedByFragment.graphql';
 
 const PostedByFragmentInline = gql`
     fragment PostedByFragment on Entry {
       postedBy {
          html_url
          login
       }
     }
   `;
 
  RepoInfo.fragments = {
    entry: gql`
      fragment RepoInfo on Entry {
          stargazers_count
          open_issues_count
        }
      ...PostedByFragment
      }
    ${PostedByFragmentFromFile}
    `,
  };
  
// ^^^ PostedByFragmentFromFile does not work but PostedByFragmentInline works

If fails with error

result += args[i].loc.source.body;
TypeError: Cannot read property 'body' of undefined

Also botch fragment looks almost the same.

@jnwng
Copy link
Contributor

jnwng commented Mar 22, 2017

@fokot thanks for reporting — after poring through your fork, i was able to reproduce the issue, and distilled it down to this line:
https://github.com/apollographql/graphql-tag/blob/master/loader.js#L27-L28

  const doc = gql`${source}`;
  const outputCode = `var doc = ${JSON.stringify(doc)};`;

basically (after checking with @stubailo), since source is now no longer enumerable, when we stringify the doc, we lose that source that is causing this failure. this is coming up now because in [email protected] we bumped our dependency on graphql from 0.6.x to 0.9.x.

since the webpack loader requires the intermediary "codegen" step, i don't think we'll be able to use source.body anymore... but not sure what to replace it with just yet.

couple of options - [email protected] should continue to work as expected, but is missing a couple of bugfixes. in the meantime, i'm looking for an alternative solution and will add a test to make sure we're capturing this particular use-case.

@jnwng jnwng added the bug label Mar 22, 2017
@jnwng
Copy link
Contributor

jnwng commented Mar 22, 2017

here's a super hacky short-term fix that i drummed up: jnwng@739722d that should unblock you while we figure out a better way to get this to work properly.

@fokot
Copy link
Author

fokot commented Mar 22, 2017

I was in hurry, so my workaround was using just plain js files but I will definitelly move to new graphql-tag when this is resolved:

>>> /PostedByFragment.js
export default gql`
   fragment PostedByFragment on Entry {
     postedBy {
        html_url
        login
     }
   }
 `;

@jnwng
Copy link
Contributor

jnwng commented May 16, 2017

this should be resolved by #65 and is available in v2.1.0

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

No branches or pull requests

2 participants