|
1 | 1 | # react-native-graphql-transformer |
2 | | -Transform GraphQL source files |
| 2 | +[](#contributors) |
| 3 | + |
| 4 | +Seamlessly use GraphQL files with react-native >= 0.45 |
| 5 | + |
| 6 | +## Foreword |
| 7 | + |
| 8 | +This package is inspired by the |
| 9 | +[react-native-typescript-transform](https://github.com/ds300/@bam.tech/react-native-graphql-transformer) |
| 10 | +repository. |
| 11 | + |
| 12 | +## Goal |
| 13 | + |
| 14 | +Use `.gql`or `.graphql` files with React Native packager for better readability |
| 15 | +and separation of concerns. |
| 16 | + |
| 17 | +**Exemple of a `.gql` file with import statement:** |
| 18 | + |
| 19 | +```gql |
| 20 | +#import "fragments/BasePost.gql" |
| 21 | + |
| 22 | +query PostListItemQuery($id: ID) { |
| 23 | + Post(id: $id) { |
| 24 | + ...BasePost |
| 25 | + } |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +### Step 1: Install |
| 32 | + |
| 33 | + yarn add -D @bam.tech/react-native-graphql-transformer |
| 34 | + |
| 35 | +### Step 2: Configure the react native packager |
| 36 | + |
| 37 | +Add this to your rn-cli.config.js (make one if you don't have one already): |
| 38 | + |
| 39 | +```js |
| 40 | +module.exports = { |
| 41 | + getTransformModulePath() { |
| 42 | + return require.resolve("@bam.tech/react-native-graphql-transformer"); |
| 43 | + }, |
| 44 | + getSourceExts() { |
| 45 | + return ["gql", "graphql"]; |
| 46 | + } |
| 47 | +}; |
| 48 | +``` |
| 49 | + |
| 50 | +If you need to run the packager directly from the command line, run the |
| 51 | +following |
| 52 | + |
| 53 | + react-native start --transformer node_modules/@bam.tech/react-native-graphql-transformer/index.js --sourceExts gql,graphql |
| 54 | + |
| 55 | +### Step 3: Write GraphQL code! |
| 56 | + |
| 57 | +## Contributors |
| 58 | + |
| 59 | +<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> |
| 60 | +<!-- prettier-ignore --> |
| 61 | +| [<img src="https://avatars1.githubusercontent.com/u/16262904?v=4" width="100px;"/><br /><sub><b>Thomas Pucci</b></sub>](https://github.com/tpucci)<br />[💻](https://github.com/bamlab/react-native-graphql-transformer/commits?author=tpucci "Code") [📖](https://github.com/bamlab/react-native-graphql-transformer/commits?author=tpucci "Documentation") [💡](#example-tpucci "Examples") | |
| 62 | +| :---: | |
| 63 | +<!-- ALL-CONTRIBUTORS-LIST:END --> |
| 64 | +## License |
| 65 | + |
| 66 | +MIT |
0 commit comments