Questions tagged [graphql-tag]

GraphQL Tag is a JavaScript template literal tag that parses GraphQL queries.

GraphQL Tag or gql is a open source template literal tag you can use to concisely write a GraphQL query that is parsed into the standard GraphQL AST.

Documentation

71 questions
83
votes
15 answers

GraphQL gql Syntax Error: Expected Name, found }

I'm attempting to set up Apollo GraphQL support in a new React project, but when I try to compile a query using gql I keep receiving the error: Syntax Error: Expected Name, found } This is generated by the following code: import gql from…
Nathan
  • 1,897
  • 2
  • 15
  • 16
61
votes
2 answers

GraphQLError: Syntax Error: Expected Name, found

I got the above error on a graphql query, I am using apollo-react by the way and using the Query component for rendering the data this is my code const GET_VEHICLE_CHECKS = gql` query getVehicleChecks($uuid: String!) { tripDetails(uuid: $uuid){ …
Malik Bagwala
  • 2,695
  • 7
  • 23
  • 38
54
votes
6 answers

GraphQL dynamic query building

I have a GraphQL server which is able to serve timeseries data for a specified source (for example, sensor data). An example query to fetch the data for a sensor might be: query fetchData { timeseriesData(sourceId: "source1") { data { …
Matt Wilson
  • 8,159
  • 8
  • 33
  • 55
8
votes
2 answers

How to get the name of a query from a `gql` object?

I use gql from graphql-tag. Let's say I have a gql object defined like this: const QUERY_ACCOUNT_INFO = gql` query AccountInfo { viewer { lastname firstname email phone id } } ` There must be a way to get…
Vladyslav Zavalykhatko
  • 15,202
  • 8
  • 65
  • 100
8
votes
1 answer

Nextjs-Graphql webpack loader: How to integrate Nextjs with Graphql loader

I am trying to integrate Nextjs with graphql-tag/loader, This is my next.config.js file: const withSass = require('@zeit/next-sass') const graphqlLoader = require('graphql-tag/loader') module.exports = withSass({ webpack: (config, { buildId, dev,…
acmoune
  • 2,981
  • 3
  • 24
  • 41
7
votes
1 answer

Is it possible to put variables inside a GraphQL-tag?

Right now I have this tag below. It's static and will always get a comment with the id of 3. Is there a possible way to put a variable inside this graphQL-tag. So I can re-use the graphQL-tag, and just change the variable ID? export const…
5
votes
2 answers

graphql-tag: how to get the actual string for the body request?

I want to use the library https://github.com/apollographql/graphql-tag I'm looking for someone smarter than me that understands how to actually use it. Say I have a GraphQL query document like so: const query = gql` { user(id: 5) { …
user2923322
  • 1,072
  • 1
  • 11
  • 25
5
votes
2 answers

graphql-codegen dynamic fields with interpolation

I'm using graphql-codegen to generate typescript types from graphql schema. I'm trying to create a fragment with dynamic fields. schema.ts This is the type generated by graphql-codegen. /** User Type */ export type UserType = { __typename?:…
in3pi2
  • 877
  • 1
  • 11
  • 22
5
votes
1 answer

Graphql-config does not recognize Apollo Graphql @client directive

I'm using Apollo Client with React, graphql-tag loaded with Webpack, and graphql-config to maintain the schema on the client. There is a file ./myclient/src/features/stats/graphql/getStart.graphql query GetStart { start @client } where start…
Adam S
  • 509
  • 10
  • 24
5
votes
1 answer

How to handle .gql file imports in Jest tests

I'm trying to test a component that imports a .gql file. When I try to build the component in a Jest file, I receive this error: ( object. anonymous function(module exports require __dirname __filename global jest) { query getUser { …
jvpcavalcante
  • 53
  • 1
  • 6
5
votes
1 answer

How to declare a module to do named imports?

I'm using graphql-tag. My files are like that. ./operation.graphql Query User { ... } ./test.ts import { User } from './operation.graphql'; /// Module ''*.graphql'' has no exported member 'User'. ./index.d.ts declare module '*.graphql' { …
left click
  • 894
  • 10
  • 21
5
votes
3 answers

How to test GraphQL queries with fragments using jest

Problem: I would like to test a GraphQL query that lives in a .graphql file like this: #import '../../fragments/Widget.graphql' query WidgetFragment($id: ID) { readWidgetFragment(id: $id) { ...Widget } } To create a GraphQL schema…
4
votes
1 answer

How can I make a custom query directive in Apollo

The GraphQL specification allows us to add custom query directives. I'm looking for some information on how can I do this. I want to create a @include like a directive, but with more elaborate logic. Apollo guide describes only adding scheme (i.e.…
s-f
  • 2,091
  • 22
  • 28
4
votes
2 answers

Why do you need graphql-tag with Apollo

Following some tutorials and examples, I integrated a GraphQL API into a simple Vue application. I'm using Apollo to interact with the API and graphql-tag's provided template literal to write the queries, like so: gql` query getUser($userId: ID)…
Criss
  • 952
  • 5
  • 17
4
votes
0 answers

Why I get Argument of undefined passed to parser was not a valid GraphQL DocumentNode?

I do import graphQL query as: import {getStudents} from'./../graphql/Queries.graphql' Queries.graphql file: query getStudents($schoolID: Int!){ allStudents(schoolId: $schoolID){ pickUpLat pickUpLng } } but when I try to pass the query…
simo
  • 23,342
  • 38
  • 121
  • 218
1
2 3 4 5