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

Can’t concat operation name #4

Open
Madumo opened this issue Nov 1, 2018 · 0 comments
Open

Can’t concat operation name #4

Madumo opened this issue Nov 1, 2018 · 0 comments

Comments

@Madumo
Copy link

Madumo commented Nov 1, 2018

A thing that i like to do is to concat the OperationName to my query:

export const OPERATION_NAME = 'MyQuery';

const query = gql`
  query ${OPERATION_NAME} {
    whatever {
      foo
      bar
    }
  }
`;

That way, I can export the operation name along with the query and when i need to use it with the refetchQueries parameters of Apollo I have a direct link between the code that ask for a query to refetch and the query itself.

That works well with graphql-tag, but when I use graphql-tag.macro instead, it crashes at runtime.

The operation name doesn’t seem to be properly concatenated to the query source code before it is passed to graphql-tag and is handled like fragments are handled. I tried to debug it and to find a fix, but my understanding of how babel internals works is lacking too much to be able to fix it.

The fix would be to figure out a way to determine if an expression is just a string and not another compiled ast and to add it to the query source before we pass it to graphql-tag.

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

1 participant