GithubHelp home page GithubHelp logo

nexus-federation-example's Introduction

nexus-federation-example's People

Contributors

deepsourcebot avatar nayaabkhan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

krlosg ken1800

nexus-federation-example's Issues

Thanks for the example

Hey thanks a lot for the example!!!

I'm trying to do this with Prisma and it's a bit unclear on some points as I can't find an example that uses a real DB.

I'm trying to connect to an external type. and put it in another type.

For example:

user now contains products. Each is in a separate DB on a separate service.

I can't figure out how to use resolveReference, or even how to resolve the data fetching.

Here's my code:

Schema.ts

onst federatedSchema = applyMiddleware(
  transformSchemaFederation(schema, {
    Query: {
      extend: true,
    },
    Mutation: {
      extend: true,
    },
    User: {
      keyFields: ['id'],
    },
    Product: {
      // extend Product {
      extend: true,
      // Product @key(fields: "id") {
      keyFields: ['id'],
      fields: {
        id: {
          external: true,
        },
      },
      // resolveReference({ id }: any, context: Context, info) {
      //   return delegateToSchema({
      //     schema: info.schema,
      //     operation: 'query',
      //     fieldName: 'productById',
      //     args: {
      //       id,
      //     },
      //     context,
      //     info,
      //   });
      // },
    },
  }),
  permissions
);

Product.ts

import { objectType } from 'nexus';
import { product as TypeName } from './typeNames';

export const User = objectType({
  name: TypeName,
  definition(t) {
    t.string('id');
  },
});

User.ts

import { objectType } from 'nexus';
import { user as TypeName, product } from './typeNames';

export const User = objectType({
  name: TypeName,
  definition(t) {
    t.model.id();
    t.model.createdAt();
    t.model.updatedAt();
    t.model.firstName();
    t.model.lastName();
    t.list.field('products', { type: product });  },
});

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.