Skip to content

Commit

Permalink
feat: support mercurius v12 (#13)
Browse files Browse the repository at this point in the history
* support mervurius v12

* fix test

* pnpmp

* remove .idea

* .gitignore

* sort import

* sort import

* run prettier

* fix readme
  • Loading branch information
trim21 authored Mar 3, 2023
1 parent 9a1dbc3 commit 4b96787
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ dist

# TernJS port file
.tern-port

.idea/
.vscode/
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ In a federated service it's useful to test if a service is extending the entity
An entity can be federated on a single field:

```ts
import { mercuriusFederationPlugin } from '@mercuriusjs/federation'

const schema = `
type Post @key(fields: "id") {
id: ID! @external
Expand All @@ -326,14 +328,13 @@ const schema = `
`

const app = fastify()
app.register(mercurius, {
app.register(mercuriusFederationPlugin, {
schema,
resolvers: {
User: {
posts: () => [{ id: 'post-id', description: 'Post description' }],
},
},
federationMetadata: true,
})

const client = createMercuriusTestClient(app)
Expand Down Expand Up @@ -379,14 +380,13 @@ const schema = `
`

const app = fastify()
app.register(mercurius, {
app.register(mercuriusFederationPlugin, {
schema,
resolvers: {
Product: {
category: () => ({ id: 'product-category', name: 'Stub category' }),
},
},
federationMetadata: true,
})

const client = createMercuriusTestClient(app)
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
},
"devDependencies": {
"@fastify/cookie": "^8.3.0",
"@mercuriusjs/federation": "^1.0.1",
"@mercuriusjs/gateway": "^1.2.0",
"@types/cookie": "^0.5.1",
"@types/node": "^14.18.32",
"@types/readable-stream": "^2.3.14",
Expand All @@ -47,7 +49,7 @@
"graphql": "^16.6.0",
"graphql-tag": "^2.12.6",
"husky": "^8.0.1",
"mercurius": "^11.0.1",
"mercurius": "^12.0.0",
"mqemitter": "^5.0.0",
"prettier": "^2.7.1",
"pretty-quick": "^3.1.3",
Expand All @@ -58,7 +60,9 @@
"peerDependencies": {
"fastify": "^4.0.0",
"graphql": "*",
"mercurius": "^11.0.0"
"@mercuriusjs/federation": "^1.0.1",
"@mercuriusjs/gateway": "^1.2.0",
"mercurius": "^12.0.0"
},
"engines": {
"node": ">=14"
Expand Down
112 changes: 94 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions test/federated-entity.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mercuriusFederationPlugin } from '@mercuriusjs/federation'
import { fastify } from 'fastify'
import mercurius from 'mercurius'
import tap from 'tap'
Expand All @@ -18,14 +19,13 @@ tap.test('returns single-key federated entity', async (t) => {
`

const app = fastify()
app.register(mercurius, {
app.register(mercuriusFederationPlugin, {
schema,
resolvers: {
User: {
posts: () => [{ id: 'post-id', description: 'Post description' }],
},
},
federationMetadata: true,
})

const client = createMercuriusTestClient(app)
Expand Down Expand Up @@ -71,14 +71,13 @@ tap.test('returns multi-key federated entity', async (t) => {
`

const app = fastify()
app.register(mercurius, {
app.register(mercuriusFederationPlugin, {
schema,
resolvers: {
Product: {
category: () => ({ id: 'product-category', name: 'Stub category' }),
},
},
federationMetadata: true,
})

const client = createMercuriusTestClient(app)
Expand Down Expand Up @@ -130,7 +129,6 @@ tap.test('throws if service is not federated', async (t) => {
posts: () => [{ id: 'post-id', description: 'Post description' }],
},
},
federationMetadata: false,
})

const client = createMercuriusTestClient(app)
Expand Down Expand Up @@ -166,14 +164,13 @@ tap.test('throws if entity is not federated', async (t) => {
`

const app = fastify()
app.register(mercurius, {
app.register(mercuriusFederationPlugin, {
schema,
resolvers: {
User: {
posts: () => [{ id: 'post-id', description: 'Post description' }],
},
},
federationMetadata: true,
})

const client = createMercuriusTestClient(app)
Expand Down

0 comments on commit 4b96787

Please sign in to comment.