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

What kind of format we need to return for supergraphsdl .I am getting errro throw new Error("Expected ".concat((0, _inspect.default)(schema), " to be a GraphQL schema.")); #27

Open
Revanth-guduru-balaji opened this issue Oct 6, 2021 · 0 comments

Comments

@Revanth-guduru-balaji
Copy link

GATEWAY.js######

const { ApolloServer } = require('apollo-server')
const { ApolloGateway } = require('@apollo/gateway')
const { get,post } = require('httpie')

async function getSupergraph() {
const res = await get(http://localhost:4007/graph)
console.log(res.data);
return {
supergraphSdl: res.data
}
}

async function startServer() {
const gateway = new ApolloGateway({
experimental_pollInterval: 30000,
async experimental_updateSupergraphSdl() {
return getSupergraph()
},
__exposeQueryPlanExperimental: false,
})

const server = new ApolloServer({
gateway,
engine: false,
subscriptions: false,
})

server.listen().then(({ url }) => {
console.log(🚀 Server ready at ${url})
})
}

startServer().catch((err) => {
console.error(err)
process.exit(1)
})
################
########Graph-api.js########

const express = require('express')
const app = express()
const port = 4007
const { readFileSync } = require('fs');
const supergraphSdl = readFileSync('./supergraph.graphql');

app.use(express.json());

app.get('/', (req, res) => {
res.end('Hello World!');
});

app.get("/graph", (req, res) => {
console.log(supergraphSdl.toString());
res.end(supergraphSdl);
});

app.listen(port, () => {
console.log(🚀Super graphAPI listening at http://localhost:${port})
});
##################
#########supergraph.graphql########

schema
@core(feature: "https://specs.apollo.dev/core/v0.2"),
@core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
{
query: Query
mutation: Mutation
}

directive @core(as: String, feature: String!, for: core__Purpose) repeatable on SCHEMA

directive @join__field(graph: join__Graph, provides: join__FieldSet, requires: join__FieldSet) on FIELD_DEFINITION

directive @join__graph(name: String!, url: String!) on ENUM_VALUE

directive @join__owner(graph: join__Graph!) on INTERFACE | OBJECT

directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on INTERFACE | OBJECT

type AddStudentResponse {
code: Int!
message: String!
student: Student
success: Boolean!
}

type Mutation {
addStudent(gender: String!, name: String!): AddStudentResponse! @join__field(graph: STUDENTS)
}

type Query {
studentDetails: [Student!]! @join__field(graph: STUDENTS)
studentDetailsbyId(id: ID!): Student! @join__field(graph: STUDENTS)
}

type Student
@join__owner(graph: STUDENTS)
@join__type(graph: STUDENTS, key: "id")
{
gender: String @join__field(graph: STUDENTS)
id: ID @join__field(graph: STUDENTS)
name: String @join__field(graph: STUDENTS)
}

enum core__Purpose {
"""
EXECUTION features provide metadata necessary to for operation execution.
"""
EXECUTION

"""
SECURITY features provide metadata necessary to securely resolve fields.
"""
SECURITY
}

scalar join__FieldSet

enum join__Graph {
STUDENTS @join__graph(name: "students" url: "http://localhost:4004/")
}

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

1 participant