All Projects â†’ guymers â†’ babel-plugin-flow-relay-query

guymers / babel-plugin-flow-relay-query

Licence: MIT license
Babel plugin which converts Flow types into Relay fragments

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to babel-plugin-flow-relay-query

Magiql
🌐 💫 Simple and powerful GraphQL Client, love child of react-query ❤️ relay
Stars: ✭ 45 (+18.42%)
Mutual labels:  relay, babel-plugin
Absinthe
The GraphQL toolkit for Elixir
Stars: ✭ 3,805 (+9913.16%)
Mutual labels:  relay, apollo-client
babel-plugin-transform-relay-hot
🔥 BabelRelayPlugin with hot reload
Stars: ✭ 28 (-26.32%)
Mutual labels:  relay, babel-plugin
vscode-graphiql-explorer
Use GraphiQL + GraphiQL Explorer to build your GraphQL operations, right from inside of VSCode.
Stars: ✭ 35 (-7.89%)
Mutual labels:  relay, apollo-client
GithubClient
Github iOS Client based on Github REST V3 API and GraphQL V4 API
Stars: ✭ 42 (+10.53%)
Mutual labels:  apollo-client
github-react-native-apollo-graphql
📱 A GitHub mobile app built with React-Native and Apollo GraphQL
Stars: ✭ 24 (-36.84%)
Mutual labels:  apollo-client
ReactNativeApolloOnlineStore
A react native online shop using Apollo client 3
Stars: ✭ 60 (+57.89%)
Mutual labels:  apollo-client
react-native-relay
🚀 demo React Native app using React Navigation and Relay with mutations and subscriptions
Stars: ✭ 20 (-47.37%)
Mutual labels:  relay
babel-plugin-inline-svg
Babel plugin to optimise and inline svg
Stars: ✭ 50 (+31.58%)
Mutual labels:  babel-plugin
apollo-link-logger
A logger for Apollo Link that resembles redux-logger
Stars: ✭ 161 (+323.68%)
Mutual labels:  apollo-client
ctrip-apollo-client
This is a client library for Apollo(A reliable configuration management system) written in Node.js.
Stars: ✭ 49 (+28.95%)
Mutual labels:  apollo-client
babel-plugin-object-styles-to-template
Babel plugin to transpile object styles to template literal
Stars: ✭ 33 (-13.16%)
Mutual labels:  babel-plugin
react-apollo-graphql
Get rid of decorators and use Apollo GraphQL queries and mutations in the simple and readable way.
Stars: ✭ 16 (-57.89%)
Mutual labels:  apollo-client
react-graphql
react-graphql 快速开发方案
Stars: ✭ 15 (-60.53%)
Mutual labels:  apollo-client
sprockets-bumble d
Sprockets plugin to transpile modern javascript using Babel, useful while migrating to ES6 modules
Stars: ✭ 32 (-15.79%)
Mutual labels:  babel-plugin
safe-relay-service
Relay Tx Service for Gnosis Safe
Stars: ✭ 48 (+26.32%)
Mutual labels:  relay
isomorphic-relay-app
Example isomorphic React-Relay-(Modern / Classic)-Router app and helper lib that connects to Artsy's GraphQL service
Stars: ✭ 13 (-65.79%)
Mutual labels:  relay
cash-flow
Application for managing cash flows written in ASP.NET Core 6 and Angular 13 (EF Core, Apollo, GraphQL, CQRS)
Stars: ✭ 27 (-28.95%)
Mutual labels:  apollo-client
apollo-resolvers
Expressive and composable resolvers for Apollostack's GraphQL server
Stars: ✭ 434 (+1042.11%)
Mutual labels:  apollo-client
trouble-training
FullStack DDD/CQRS with GraphQL workshop including distributed tracing and monitoring. This shows the configuration from React frontend to .Net backend.
Stars: ✭ 271 (+613.16%)
Mutual labels:  relay

babel-plugin-flow-relay-query

Babel plugin which converts Flow types into GraphQL fragments.

Installation

npm install --save-dev babel-plugin-flow-relay-query

Usage

Instead of importing babel-relay-plugin, import babel-plugin-flow-relay-query

Replace

var getBabelRelayPlugin = require("babel-relay-plugin");

with

var getBabelRelayPlugin = require("babel-plugin-flow-relay-query");

Example

Create a marker function called generateFragmentFromProps or generateFragmentFromPropsFor:

type FragmentOptions = {
  name?: string;
  type?: string;
  templateTag?: string;
  directives?: {
    [name: string]: { [arg: string]: boolean|number|string };
  };
}

function generateFragmentFromProps(options?: FragmentOptions): Function {}
function generateFragmentFromPropsFor(component: ReactClass<*>, options?: FragmentOptions): Function {}

Or just import one of the ones that are shipped with the plugin:

import { generateFragmentFromProps } from "babel-plugin-flow-relay-query/lib/markers";
import { generateFragmentFromPropsFor } from "babel-plugin-flow-relay-query/lib/markers";

If a fragment type is not provided in the options then it will default to the key in the fragments object, capitalized.

import React from "react";
import Relay from "react-relay";
import { generateFragmentFromProps } from "babel-plugin-flow-relay-query/lib/markers";

type ArticleProps = {
  article: {
    title: string;
    posted: string;
    content: string;

    author: {
      name: string;
      email: string;
    }
  }
};

class Article extends React.Component<void, ArticleProps, void> {
  render() {
    const { article } = this.props;
    return (
      <div>
        <ArticleTitle article={article} />
        <div>{article.author.name} [{article.author.email}]</div>
        <div>{article.content})</div>
      </div>
    );
  }
}

export default Relay.createContainer(Article, {
  fragments: {
    article: generateFragmentFromProps(),
  },
});

The article fragment will be transformed into:

export default Relay.createContainer(Article, {
  fragments: {
    article: () => Relay.QL`
      fragment on Article {
        title,
        posted,
        content,
        author {
          name,
          email
        },
        ${ArticleTitle.getFragment("article")}
      }
    `
  }
});

Also supports class properties and functional components:

class Article extends React.Component {
  props: ArticleProps;
  ...
}
const Article = ({ article }: ArticleProps) => (
  <div>
    <div>{article.title} ({article.posted})</div>
    <div>{article.author.name} [{article.author.email}]</div>
    <div>{article.content})</div>
  </div>
);

This plugin can also create GraphQL strings for Apollo:

First set apollo generation options globally:

var ChildFragmentTransformations = require("babel-plugin-flow-relay-query/lib/ChildFragmentTransformations");
var babelRelayPlugin = require("babel-plugin-flow-relay-query");
const schema = require("??/schema.json");
module.exports = babelRelayPlugin(schema.data, {}, {
  defaultTemplateTag: "gql",
  defaultFragmentName: ChildFragmentTransformations.apolloFragmentName,
  childFragmentTransformations: ChildFragmentTransformations.apollo
});
import React from "react";
import gql from "graphql-tag";
import { generateFragmentFromPropsFor } from "babel-plugin-flow-relay-query/lib/markers";

type ArticleProps = {
  article: {
    title: string;
    content: string;
  }
};

class Article extends React.Component {
  props: ArticleProps;

  render() {
    const { article } = this.props;
    return (
      <div>
        <ArticleTitle article={article} />
        <div>{article.author.name} [{article.author.email}]</div>
        <ArticleBody article={article} />
        <Footer />
      </div>
    );
  }
}

Article.fragments = {
  article: generateFragmentFromPropsFor(Article)
};

export default Article;
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].