All Projects β†’ bamlab β†’ React Native Graphql Transformer

bamlab / React Native Graphql Transformer

Licence: mit
Transform GraphQL source files

Programming Languages

javascript
184084 projects - #8 most used programming language

react-native-graphql-transformer

All Contributors

Seamlessly use GraphQL files with react-native >= 0.45

Foreword

This package is inspired by the react-native-typescript-transform repository.

Goal

Use .gqlor .graphql files with React Native packager for better readability and separation of concerns.

Exemple of a .gql file with import statement:

#import "fragments/BasePost.gql"

query PostListItemQuery($id: ID) {
  Post(id: $id) {
    ...BasePost
  }
}

Usage

Step 1: Install

yarn add -D @bam.tech/react-native-graphql-transformer

Step 2: Configure the react native packager

Add this to your rn-cli.config.js (make one if you don't have one already):

react-native 0.57 or later

const { getDefaultConfig } = require('metro-config');

module.exports = (async () => {
  const {
    resolver: { sourceExts },
  } = await getDefaultConfig();
  return {
    transformer: {
      babelTransformerPath: require.resolve(
        '@bam.tech/react-native-graphql-transformer'
      ),
    },
    resolver: {
      sourceExts: [...sourceExts, 'gql', 'graphql'],
    },
  };
})();

react-native 0.56 or earlier

module.exports = {
  getTransformModulePath() {
    return require.resolve('@bam.tech/react-native-graphql-transformer');
  },
  getSourceExts() {
    return ['gql', 'graphql'];
  }
};

Step 3: Write GraphQL code!

Contributors


Thomas Pucci

πŸ’» πŸ“– πŸ’‘

TychoTa

πŸ’»

ClΓ©ment Taboulot

πŸ’»

arolson101

πŸ’‘

ajubin

πŸ’»

Gerard de Brieder

πŸ›

mike castleman

πŸ“–

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].