All Projects → 0xR → Graphql Transform Federation

0xR / Graphql Transform Federation

Convert your existing GraphQL schema into a federated schema

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Graphql Transform Federation

Graphiql
GraphiQL & the GraphQL LSP Reference Ecosystem for building browser & IDE tools.
Stars: ✭ 12,985 (+7866.26%)
Mutual labels:  graphql
Pop
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder
Stars: ✭ 160 (-1.84%)
Mutual labels:  graphql
Examples
Examples of Mock Service Worker usage with various frameworks and libraries.
Stars: ✭ 163 (+0%)
Mutual labels:  graphql
Next Apollo Auth
Authentication Boilerplate with Next.js and Apollo GraphQL
Stars: ✭ 159 (-2.45%)
Mutual labels:  graphql
Graphql Rails Blog
Blog App built with Rails 5, React and GraphQL
Stars: ✭ 160 (-1.84%)
Mutual labels:  graphql
React Admin Low Code
react-admin (via ra-data-hasura-graphql provider) + hasura = :)
Stars: ✭ 161 (-1.23%)
Mutual labels:  graphql
Babel Plugin Graphql Tag
Compiles GraphQL tagged template strings using graphql-tag.
Stars: ✭ 156 (-4.29%)
Mutual labels:  graphql
Parser
A lexer and parser for GraphQL in .NET
Stars: ✭ 163 (+0%)
Mutual labels:  graphql
Dataloader Php
DataLoaderPhp is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.
Stars: ✭ 160 (-1.84%)
Mutual labels:  graphql
Vendure
A headless GraphQL ecommerce framework for the modern web
Stars: ✭ 2,961 (+1716.56%)
Mutual labels:  graphql
Ferry
Stream-based strongly typed GraphQL client for Dart
Stars: ✭ 160 (-1.84%)
Mutual labels:  graphql
Webtau
Webtau (short for web test automation) is a testing API, command line tool and a framework to write unit, integration and end-to-end tests. Test across REST-API, Graph QL, Browser, Database, CLI and Business Logic with consistent set of matchers and concepts. REPL mode speeds-up tests development. Rich reporting cuts down investigation time.
Stars: ✭ 156 (-4.29%)
Mutual labels:  graphql
Cms Mobile
A flutter project for amfoss cms
Stars: ✭ 162 (-0.61%)
Mutual labels:  graphql
Portara
Portara directive is a rate limiter / throttler for GraphQL
Stars: ✭ 158 (-3.07%)
Mutual labels:  graphql
Graphql Builder
GraphQL client library for Clojure and ClojureScript
Stars: ✭ 163 (+0%)
Mutual labels:  graphql
Lacinia Pedestal
Expose Lacinia GraphQL as Pedestal endpoints
Stars: ✭ 157 (-3.68%)
Mutual labels:  graphql
Frisky
🍿 Open Source GraphQL API for Online Shows
Stars: ✭ 161 (-1.23%)
Mutual labels:  graphql
Workshops
Workshops organized to introduce students to security, AI, AR/VR, hardware and software
Stars: ✭ 162 (-0.61%)
Mutual labels:  graphql
Express Graphql Typescript Boilerplate
A starter kit for building amazing GraphQL API's with TypeScript and express by @w3tecch
Stars: ✭ 163 (+0%)
Mutual labels:  graphql
Wp Graphql Gutenberg
Query gutenberg blocks with wp-graphql
Stars: ✭ 158 (-3.07%)
Mutual labels:  graphql

graphql-transform-federation

If you want to use GraphQL federation, but you can't rebuild your current GraphQL schema, you can use this transform to add GraphQL federation functionality to an existing schema. You need this when you are using a managed GraphQL service or a generated schema which doesn't support federation (yet).

If you are using apollo-server or another schema builder that supports federation you don't need this transform you should add the federation directives directly.

This transform will add the resolvers and directives to conform to the federation specification. Much of the federation sourcecode could be reused ensuring it is compliant to the specification.

Check out the blogpost introducing graphql-tranform-federation for more background information.

Architecture diagram for graphql-transform-federation

Usage

You can use this transform on a local or a remote GraphQL schema. When using a remote schema your service acts a middleware layer as shown in the diagram above. Check the remote schema documentation for how to get an executable schema that you can use with this transform.

The example below shows a configuration where the transformed schema extends an existing schema. It already had a resolver productById which is used to relate products between the two schemas. This example can be started using npm run example.

import { transformSchemaFederation } from 'graphql-transform-federation';
import { delegateToSchema } from 'graphql-tools';

const schemaWithoutFederation = // your existing executable schema

const federationSchema = transformSchemaFederation(schemaWithoutFederation, {
  Query: {
    // Ensure the root queries of this schema show up the combined schema
    extend: true,
  },
  Product: {
    // extend Product {
    extend: true,
    // Product @key(fields: "id") {
    keyFields: ['id'],
    fields: {
      // id: Int! @external
      id: {
        external: true
      }
    },
    resolveReference({ id }, context, info) {
      return delegateToSchema({
        schema: info.schema,
        operation: 'query',
        fieldName: 'productById',
        args: {
          id,
        },
        context,
        info,
      });
    },
  },
});

To allow objects of an existing schema to be extended by other schemas it only needs to get @key(...) directives.

const federationSchema = transformSchemaFederation(schemaWithoutFederation, {
  Product: {
    // Product @key(fields: "id") {
    keyFields: ['id'],
  },
});

API reference

import { GraphQLSchema } from 'graphql';
import { GraphQLReferenceResolver } from '@apollo/federation/dist/types';

interface FederationFieldConfig {
  external?: boolean;
  provides?: string;
  requires?: string;
}

interface FederationFieldsConfig {
  [fieldName: string]: FederationFieldConfig;
}

interface FederationObjectConfig<TContext> {
  // An array so you can add multiple @key(...) directives
  keyFields?: string[];
  extend?: boolean;
  resolveReference?: GraphQLReferenceResolver<TContext>;
  fields?: FederationFieldsConfig;
}

interface FederationConfig<TContext> {
  [objectName: string]: FederationObjectConfig<TContext>;
}

function transformSchemaFederation<TContext>(
  schema: GraphQLSchema,
  federationConfig: FederationConfig<TContext>,
): GraphQLSchema;

npm run example

Runs 2 GraphQL servers and a federation gateway to combine both schemas. Transformed-server is a regular GraphQL schema that is tranformed using this library. The federation-server is a federation server which is extended by a type defined by the transformed-server. The gateway combines both schemas using the apollo gateway.

npm run example:watch

Runs the example in watch mode for development.

npm run test

Run the tests

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].