apollo-fetch icon indicating copy to clipboard operation
apollo-fetch copied to clipboard

[feature idea] graphql-tag support.

Open gviligvili opened this issue 7 years ago • 5 comments

I'm using apollo-fetch in my nodeJS server, to fetch data from my micro services which are also in graphql.

-- works fine. Thank you.

but the thing is that graphql-tag suppose to let us use fragments + let us use plugins which allow auto complete for fields and fragments. (which is EXTREMELY helpful in our huge schemas).

apollo client support it, so I though apollo-fetch would support it too, but I when I try to use apollo-fetch with graphql-tag - I get invalid json response from the microservice. (Java GraphQL). without graphql - works great, but doesn't let me use very helpful features.

Thank you !

example : works :

    const query = `
  query CurrentUser {
    currentUser {
      login,
    }
  }
`

doesn't work :

 import gql from 'graphql-tag';
 
 const query = gql`
  query CurrentUser {
    currentUser {
      login,
    }
  }
`

(Or is the java server responsibility? maybe I need to add him a tool to parse ast ?)

gviligvili avatar Oct 02 '17 23:10 gviligvili

It's unfortunate this issue has gone so long unanswered. I came across the same need to enable template syntax highlighting with the gql tag and vim.

If you take a look at the tests for apollo-fetch, you'll see the use of the gql tag and the function print().

So in your case, it would be:

import { createApolloFetch } from 'apollo-fetch';
import { print } from 'graphql';
import gql from 'graphql-tag';

const query = gql`
  query CurrentUser {
    currentUser {
      login,
    }
  }
`

const fetcher = createApolloFetch({ ... });
fetcher({ query: print(query) }).then(...).catch(...);

codemonkey800 avatar Mar 23 '18 05:03 codemonkey800

Any knowledge on when this might be implemented? Kind of a buzzkill to have to use the gql string literal.

cereallarceny avatar Apr 07 '18 23:04 cereallarceny

@codemonkey800 Thanks for the workaround. I'm also waiting for the support of graphql-tag

laukaichung avatar May 30 '18 09:05 laukaichung

I'm curious about the reason why gql is not supported. It caught me completely by surprise, and the absence of gql before the template literal in the readme queries is NOT obvious, so I scratched my head for a few hours wondering why it wasn't working. A mention in the readme about stringifying graphql-tag queries or leaving gql out would be very welcome indeed.

danieldunderfelt avatar Jun 01 '18 08:06 danieldunderfelt

As mentioned in #80 (and since #193 now also in the main README) this library is deprecated in favor of apollo-link.

Is migrating to apollo-link a viable solution for anyone in here?

ctavan avatar Jun 01 '18 08:06 ctavan