You can use .graphql files even if you can't use webpacksteemCreated with Sketch.

in programming •  7 years ago 

This is mainly an announcement post for people already using GraphQL, so I'm not going into detail about what GraphQL is.

'Vanilla' GraphQL:

Most people using GraphQL just use the gql template literal tag.

// use.js
import gql from 'graphql-tag'
const query = gql`query myQuery { myField }`
console.log(query)

Separate files with webpack loader:

The above can quickly litter your code though, so many people prefer to use the webpack loader offered by the graphql-tag package. This allows moving GraphQL code into its own files for more separation of concerns, syntax highlighting, etc.

// query.gql
query myQuery { myField }

// use.js
import query from './query.graphql'
console.log(query)

Other Options:

Not everyone can use webpack. A few cases where this might be true are:

  • Using Next.js
  • Using React Native
  • Using Create-React-App before ejecting your app

I've created a couple of packages for these scenarios. For the first two cases (or any case where you have access to babel plugins but not webpack) there's babel-plugin-inline-import-graphql-ast

For the third case, I made a wrapper package around the first, react-app-rewire-inline-import-graphql-ast

If you try either of these out, let me know what you think!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @detrohutt! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @detrohutt! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!