yusinto/relay-compiler-plus

Option to keep operation.text in the generated queries?

caffodian opened this issue · 7 comments

Is there a way of keeping operation.text in the generated queries?

I'm working around it for now, but I can see the null text being a problem, for example, if you use a mock network layer for testing, or want to turn off the query-by-ID in some environments without re-compiling all the queries using the standard relay-compiler.

(For example, we're thinking of only enforcing query-by-ID on live)

thanks, btw! This lib looks like a good start for what I want to do - hopefully some PRs when I figure things out in the near future.

Now that I've spent some time looking into this,

it looks like the culprit is in here:

https://github.com/facebook/relay/blob/b6490223fe19e9e9894102182a52ba950a5775ba/packages/relay-compiler/codegen/writeRelayGeneratedFile.js#L106

which is somewhat unfortunate. May need to try something else

@caffodian thanks for the comment! In src/compiler/formatGeneratedModule.js line 43 there is a commented line:

// const devOnlyText = devTextGenerator ? devTextGenerator(objectName) : '';

The original code uses this in conjunction with an IS_DEV flag to still keep the query text for debugging/testing purposes.

It's definitely possible to keep this, I just have to investigate further and see how we can do it, possibly introducing something similar to IS_DEV.

I've been looking at it too. From my attempts at looking at the relay-compiler code, it looks like they no longer have that line in formatGeneratedModule.js

I definitely don't know much about relay-compiler yet, though. I could be wrong.

Hi, thanks for this again. I've been quietly using it while finding workarounds to my original issue. Any ideas on this one, yet?

cheers

Hi @caffodian I haven't revisited this since last December. I have upgraded rcp to work with the latest graphql version and relay compiler though, and those IS_DEV are gone from relay compiler. I think I should be able to include the original operation text in dev mode. Let me take a look. Thanks for reporting!

v1.7.9 now supports this. By default it looks for the NODE_ENV environment variable and will include the operation text if it's not production. Please try and let me know if this works for you. Thanks!

@caffodian

Thanks! will give it a try