Prisma1: `prisma.$graphql` could accept not only string, but also `graphql-tag`ed object

Created on 20 Dec 2018  路  5Comments  路  Source: prisma/prisma1

Is your feature request related to a problem? Please describe.
In prisma.$graphql(query, variables) now query could only be string, not query object generated via graphql-tag.

Describe the solution you'd like
It would be nice to be able to do this:

import gql from 'graphql-tag'
const QUERY = gql` 
  query.....
`
prisma.$graphql(query)
kinfeature rf1-draft

Most helpful comment

@pantharshit00 Thank you for the quick response.

It's not only for syntax highlighting but also for linting. For example, with eslint-plugin-graphql + vscode eslint extension, we could lint errors (graphql syntax errors, non-existing fields, etc.) in graphql-tagged strings:

image

image

But this linting by default cannot detect raw strings even we have /* GraphQL */ before them.

And also, sometimes we need to use the same query, or mutation, or especially a fragment, in both an apollo/graphql-request api (which require a graphql-tagged object) and a prisma.$graphql api (which requires a raw string). Currently for this situation I have to define two versions for the same thing, which seems quite ugly and awkward:

import gql from 'graphql-tag'

export const JOB_FOR_LOCK_CHECK_STRING = /* GraphQL */ `
  id
  requiredJobs {
    id
    title
    userJobRecords(where: { userId: $userId }) {
      id
      userId
      jobId
      score
    }
  }
`

export const JOB_FOR_LOCK_CHECK = gql([`fragment JobForLockCheck on Job { ${JOB_FOR_LOCK_CHECK_STRING} }`])

All 5 comments

Hi @beeplin,

Can you tell me a use case of supporting the graphql tag here? If you are concerned about syntax highlighting you can do that in regular strings using a simple comment like so:

const QUERY = /* GraphQL */` 
  query.....
`
prisma.$graphql(query)

@pantharshit00 Thank you for the quick response.

It's not only for syntax highlighting but also for linting. For example, with eslint-plugin-graphql + vscode eslint extension, we could lint errors (graphql syntax errors, non-existing fields, etc.) in graphql-tagged strings:

image

image

But this linting by default cannot detect raw strings even we have /* GraphQL */ before them.

And also, sometimes we need to use the same query, or mutation, or especially a fragment, in both an apollo/graphql-request api (which require a graphql-tagged object) and a prisma.$graphql api (which requires a raw string). Currently for this situation I have to define two versions for the same thing, which seems quite ugly and awkward:

import gql from 'graphql-tag'

export const JOB_FOR_LOCK_CHECK_STRING = /* GraphQL */ `
  id
  requiredJobs {
    id
    title
    userJobRecords(where: { userId: $userId }) {
      id
      userId
      jobId
      score
    }
  }
`

export const JOB_FOR_LOCK_CHECK = gql([`fragment JobForLockCheck on Job { ${JOB_FOR_LOCK_CHECK_STRING} }`])

Thanks for the reply.

Yes, linting is a legit use case for this.

Implementing this will require a small change in http-link-dataloader using the print function from graphql. I can do a PR for it but I need approval for that /cc @timsuchanek

Have just come across this too. Support for graphql-tag would be great.

Am I right that this will also support *.graphql files where you can benefit from other things like #import ... etc.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Fi1osof picture Fi1osof  路  3Comments

thomaswright picture thomaswright  路  3Comments

marktani picture marktani  路  3Comments

hoodsy picture hoodsy  路  3Comments

ragnorc picture ragnorc  路  3Comments