Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apollo Federation is not working with this approach #2

Open
mdv27 opened this issue Mar 9, 2023 · 1 comment
Open

Apollo Federation is not working with this approach #2

mdv27 opened this issue Mar 9, 2023 · 1 comment

Comments

@mdv27
Copy link

mdv27 commented Mar 9, 2023

Thanks for creating this repository. I am able to create subgraph with azure function using the similar styles. I am unable to create the gateway with azure function which imports the subgraph. Gateway works fine as nestjs application server but does not when exposed as azure function. I am getting 404 error on http://localhost:7071/api/graphql

Gateway function.json

{
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "route": "graphql"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ],
  "scriptFile": "../dist/main/index.js"
}

Gateway index.ts

import { Context, HttpRequest } from "@azure/functions";
import { AzureHttpAdapter } from "@nestjs/azure-func-http";
import { createApp } from "../src/main";

export default function (context: Context, req: HttpRequest) {
  context.res = {
    headers: {
      "Content-Type": "application/json"
    }
  };

    AzureHttpAdapter.handle(createApp, context, req);    
}

main.js imported in index.ts

import { INestApplication, ValidationPipe } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";

export async function createApp(): Promise<INestApplication> {
  const app = await NestFactory.create(AppModule);
  app.useGlobalPipes(new ValidationPipe());
  app.enableCors();  
  app.setGlobalPrefix("api");
  await app.init();  
  return app;
}

app.module.ts

import { IntrospectAndCompose } from '@apollo/gateway';
import { ApolloGatewayDriver, ApolloGatewayDriverConfig } from '@nestjs/apollo';
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [
    GraphQLModule.forRoot<ApolloGatewayDriverConfig>({
      driver: ApolloGatewayDriver,
      gateway: {
        supergraphSdl: new IntrospectAndCompose({
          subgraphs: [
            { name: 'servicenow-subgraph-api', url: 'http://localhost:4000/api/graphql' }
          ]
        })
      }
    })
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
@agmoss
Copy link
Owner

agmoss commented Mar 12, 2023

Hi @mdv27

Thanks for flagging this. I have yet to try using this template with the apollo federation approach. Furthermore, this template is 5 major semvers behind the current @nestjs/graphql. Thus, the approach will run into some problems.

I am game to investigate and ideally upgrade this repo to reflect current changes in the nestjs and gql ecosystem. Do you have a minimum reproducible example you can share with me? Thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants