choojs / nanographql

Tiny graphQL client library
MIT License
421 stars 25 forks source link

support fragment? #8

Open yuu2lee4 opened 6 years ago

yuu2lee4 commented 6 years ago

support fragment?

Ayc0 commented 6 years ago

If the fragment is within the query, it should work

lunchboxer commented 5 years ago

Using the template string variable expansion doesn't work with nanographql

export const GET_LESSONS = gql`
  query {
    lessons {
      ...LessonFields
    }
  }
${LessonFields}`

The above leads to a query with nothing where the fragment should be.

LeviSchuck commented 5 years ago

It is being treated as a tagged template literal, but it is not coded to handle parameters like that.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Instead you can do below, evaluate it before it goes to the function


gql(`query .... ${fragment}`)