Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/federation.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,22 @@ function buildFederationSchema (schema, { isGateway } = {}) {
isGateway
)

if (isGateway) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required; otherwise, the CI fails.
The same issue is also on the main branch

const seenDirectives = {}
for (const definition of definitions) {
if (definition.kind === Kind.DIRECTIVE_DEFINITION) {
const name = definition.name.value
if (seenDirectives[name]) {
if (print(seenDirectives[name]) !== print(definition)) {
throw new MER_ERR_GQL_FEDERATION_DUPLICATE_DIRECTIVE(name)
}
} else {
seenDirectives[name] = definition
}
}
}
}

// before we validate the federationSchema, we want to remove the _service field from the extended query,
// if there is one, as this field should be excluded from the validation to provide broader support
// for different federation implementations => https://github.com/mercurius-js/mercurius/issues/643
Expand Down
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
"version": "5.1.1",
"description": "A plugin for mercurius federation",
"main": "index.js",
"types": "index.d.ts",
"types": "types/index.d.ts",
"files": [
"index.js",
"index.d.ts",
"types/index.d.ts",
"lib"
],
"scripts": {
"lint": "npm run lint:standard && npm run lint:typescript",
"lint:fix": "standard --fix",
"lint:standard": "standard | snazzy",
"lint:typescript": "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin test/types/*.ts",
"lint:typescript": "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin types/**/*.ts",
"example": "node example/index.js",
"test": "npm run lint && npm run test:unit && npm run test:types",
"test:unit": "node --test",
"test:cov": "c8 node --test",
"test:types": "tsd",
"test:types": "tstyche",
"prepare": "husky"
},
"repository": {
Expand Down Expand Up @@ -52,12 +52,9 @@
"mqemitter": "^7.0.0",
"snazzy": "^9.0.0",
"standard": "^17.0.0",
"tsd": "^0.33.0",
"tstyche": "^7.1.0",
"ws": "^8.11.0"
},
"tsd": {
"directory": "test/types"
},
"lint-staged": {
"*.{js,jsx}": "standard --cache --fix"
},
Expand Down
46 changes: 0 additions & 46 deletions test/types/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion index.d.ts → types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FastifyInstance } from 'fastify'
import { MercuriusOptions } from 'mercurius'
import {
DocumentNode
} from 'graphql/language/ast';
} from 'graphql/language/ast'

export interface buildFederationSchemaOptions {
isGateway?: boolean
Expand Down
44 changes: 44 additions & 0 deletions types/index.tst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Fastify from 'fastify'
import gql from 'graphql-tag'
import { GraphQLSchema } from 'graphql/index.js'
import { expect } from 'tstyche'

import { buildFederationSchema, mercuriusFederationPlugin } from '..'

const schema = `
extend type Query {
me: User
}

type User @key(fields: "id") {
id: ID!
name: String
username: String
}
`

const schema2 = `
extend type Query {
you: User
}
`

expect(buildFederationSchema(schema)).type.toBe<GraphQLSchema>()
expect(buildFederationSchema(gql(schema))).type.toBe<GraphQLSchema>()
expect(buildFederationSchema([gql(schema), gql(schema2)])).type.toBe<GraphQLSchema>()
expect(buildFederationSchema(schema, {})).type.toBe<GraphQLSchema>()
expect(buildFederationSchema(schema, { isGateway: true })).type.toBe<GraphQLSchema>()

expect(buildFederationSchema).type.not.toBeCallableWith(schema, { isGateway: 'hello' })

const app = Fastify()

app.register(mercuriusFederationPlugin, {
schema,
graphiql: true
})

expect(app.register).type.not.toBeCallableWith(mercuriusFederationPlugin, {
schema: buildFederationSchema(schema),
graphiql: true
})
Loading