GithubHelp home page GithubHelp logo

spantree / nexus-federation-plugin Goto Github PK

View Code? Open in Web Editor NEW
3.0 9.0 1.0 64 KB

Nexus plugin providing integration with Apollo Federation.

License: MIT License

TypeScript 100.00%
graphql typescript nexus graphql-nexus graphql-schema graphql-federation graphql-apollo apollographql

nexus-federation-plugin's Introduction

nexus-federation-plugin

A Nexus plugin to integrate Apollo Federation with Nexus Schema.

Install

yarn add nexus-federation-plugin
or
npm i nexus-federation-plugin

API

nexus plugin

import { makeSchema } from 'nexus'
import { nexusPluginFederation } from 'nexus-federation-plugin'

export const nexusSchema = makeSchema({
  types,
  plugins: [nexusPluginFederation], // add plugin here
  outputs: {
    schema: __dirname + '/generated/schema.graphql',
    typegen: __dirname + '/generated/nexus.ts',
  },
  contextType: {
    module: join(__dirname, 'context.ts'),
    export: 'Context',
  },
})

Transform nexus schema to Federation

import { ApolloServer } from 'apollo-server'
import {
  transformSchemaFederation,
  printTransformedSchema,
} from 'nexus-federation-plugin'

import { createContext } from './context'
import { nexusSchema } from './nexusSchema'

const server = new ApolloServer({
  // warp nexus schema with our function
  schema: transformSchemaFederation(nexusSchema),
  context: createContext,
})

server.listen().then(({ url }) => {
  // you can print Transformed Schema with our function
  // it's take two args
  // 1- server instance
  // 2- create file path default `src/generated`
  printTransformedSchema(server)
  console.log(`🚀  Server ready at ${url}`)
})

Usage

Like graphql-transform-federation you can pass configration to nexus objectType

import { objectType } from 'nexus'

export const User = objectType({
  name: 'User',
  keyFields: ['id'],
  fieldDirectives: {
    id: {
      external: true,
      requires: 'email name',
    },
    email: {
      external: true,
    },
  },
  resolveReference: (parent, ctx) => {},
  definition(t) {
    t.nonNull.int('id')
    t.nonNull.string('email')
    t.string('name')
  },
})

nexus-federation-plugin's People

Contributors

ahmedelywa avatar jdugan1024 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

gurvancampion

nexus-federation-plugin's Issues

add tests

Before we release this code it would be good to have a basic test for this code.

Improve docs

The docs are just the README so far. Improve documentation.

Error: Cannot find module 'prettier'

When using this package without installing prettier as a dependency, this package will throw an error:

Error: Cannot find module 'prettier'
Require stack:

  • /Users/mleon/Workspace/playground/api/node_modules/nexus-federation-plugin/dist/nexus-federation-plugin.cjs.development.js
    ...

I can provide the code of the project upon request.

Possible solutions are either move prettier from devDependencies to dependencies or remove the usage of prettier in the 'printTransformedSchema' function.

Incompatible NexusPlugin types between nexus 1.3.0 and nexus-federation-plugin 0.0.12

I wanted to use your plugin in an existing Typescript project where we already have nexus 1.3.0 in place, and already when I tried adding it as a plugin in the makeSchema function call, I got a type error:

Der Typ "import(".../node_modules/nexus-federation-plugin/node_modules/nexus/dist/plugin").NexusPlugin" kann dem Typ "import(".../node_modules/nexus/dist/plugin").NexusPlugin" nicht zugewiesen werden.
  Die Typen von "config.fieldDefTypes" sind zwischen diesen Typen nicht kompatibel.
    Der Typ "import(".../node_modules/nexus-federation-plugin/node_modules/nexus/dist/plugin").StringLike | import(".../node_modules/nexus-federation-plugin/node_modules/nexus/dist/plugin").StringLike[] | undefined" kann dem Typ "import(".../node_modules/nexus/dist/plugin").StringLike | import(".../node_modules/nexus/dist/plugin").StringLike[] | undefined" nicht zugewiesen werden.
      Der Typ "PrintedGenTyping" kann dem Typ "StringLike | StringLike[] | undefined" nicht zugewiesen werden.
        Der Typ "import("...node_modules/nexus-federation-plugin/node_modules/nexus/dist/utils").PrintedGenTyping" kann dem Typ "import(".../node_modules/nexus/dist/utils").PrintedGenTyping" nicht zugewiesen werden.
          Die Eigenschaft "config" ist geschützt, Typ "PrintedGenTyping" ist aber keine von "PrintedGenTyping" abgeleitete Klasse.ts(2322)

(Sorry for the German)

It is basically complaining, that the NexusPlugin types are not compatible.

prepare for open source release

  • add LICENSE
  • add docs/PULL_REQUEST_TEMPLATE.md
  • add docs/CONTRIBUTING.md
  • review / update README
  • rename master -> main
  • improve docs
  • test examples
  • setup CI to do linting checks
  • add tests (see #2)
  • create NPM project
  • add CI/CD to build and publish on tag
  • tag first release

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.