-
Notifications
You must be signed in to change notification settings - Fork 5
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
Federation: Add support for federationMetadata
for executable schemas
#6
Comments
federationMetadata
for non string schemasfederationMetadata
for executable schemas
I would like to do have that too! Would you like to send a PR? |
Yes I'd like to, but it could take a while because ATM I don't have so much time to work on it. If somebody else picks it up in the meantime, that's fine for me. |
I've made a dirty solution for this problem to provide const { makeExecutableSchema } = require("@graphql-tools/schema")
const fs = require("fs")
const makeGatewayExecutableSchema = async ({
schemaPath,
schemaString,
resolvers,
}) => {
const serviceInfo = `
type Service {
sdl: String
}
type Query {
_service: Service
}
type Mutation {
_service: Service
}
type Subscription {
_service: Service
}
`
let schema
if (schemaPath) {
try {
schema = await fs.readFileSync(schemaPath, "utf-8")
} catch (e) {
console.log(e)
throw Error("Can't load schema file")
}
} else {
schema = schemaString
}
// TODO: check if there are type query and swap to extend
if (
schema.indexOf("extend type Query") === -1 &&
schema.indexOf("type Query") !== -1
) {
throw Error(
`You can't have 'type Query' in your schema,
only 'extend type Query' and so on with mutations and subscriptions`
)
}
resolvers.Query._service = () => {
return { sdl: `${schema}` }
}
return makeExecutableSchema({
typeDefs: serviceInfo + schema,
resolvers,
})
} Edit: Updated, it should work fine for many services, I've also made temporary module |
Hello!
As for now the
federationMetadata
can be enabled only on string schemas.Would be useful to support also "executable" schemas.
The text was updated successfully, but these errors were encountered: