-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dont install peer dependencies automatically with npm in Docker (#412)
Co-authored-by: theguild-bot <[email protected]>
- Loading branch information
1 parent
17e7475
commit 0d7b42d
Showing
40 changed files
with
8,698 additions
and
1,531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphql-hive/gateway': patch | ||
--- | ||
|
||
Dont install peer dependencies automatically with npm in Docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM gateway_e2e | ||
|
||
RUN npm i @envelop/operation-field-permissions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useOperationFieldPermissions } from '@envelop/operation-field-permissions'; | ||
import { defineConfig, GatewayContext } from '@graphql-hive/gateway'; | ||
|
||
export const gatewayConfig = defineConfig({ | ||
plugins: () => [ | ||
useOperationFieldPermissions({ | ||
getPermissions(ctx: GatewayContext) { | ||
const auth = ctx.request.headers.get('authorization'); | ||
if ( | ||
auth === | ||
'Bearer TOKEN' /** NOTE: proper token validity check goes here */ | ||
) { | ||
// allow all fields | ||
return new Set(['*']); | ||
} | ||
// allow only introspection | ||
return new Set(['Query.registrationOpen']); | ||
}, | ||
}) as any, // TODO: fix generic in envelop | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM gateway_e2e_bun | ||
|
||
RUN bun i @envelop/operation-field-permissions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { | ||
defineConfig, | ||
loadGraphQLHTTPSubgraph, | ||
} from '@graphql-mesh/compose-cli'; | ||
import { Opts } from '@internal/testing'; | ||
|
||
const opts = Opts(process.argv); | ||
|
||
export const composeConfig = defineConfig({ | ||
subgraphs: [ | ||
{ | ||
sourceHandler: loadGraphQLHTTPSubgraph('users', { | ||
endpoint: `http://localhost:${opts.getServicePort('users')}/graphql`, | ||
}), | ||
}, | ||
], | ||
}); |
100 changes: 100 additions & 0 deletions
100
e2e/operation-field-permissions/operation-field-permissions.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { createTenv } from '@internal/e2e'; | ||
import { expect, it } from 'vitest'; | ||
|
||
const { gateway, service } = createTenv(__dirname); | ||
|
||
it('should allow checking registration but disallow "me" when not authenticated', async () => { | ||
const { execute } = await gateway({ | ||
supergraph: { | ||
with: 'mesh', | ||
services: [await service('users')], | ||
}, | ||
}); | ||
|
||
await expect( | ||
execute({ | ||
query: /* GraphQL */ ` | ||
{ | ||
registrationOpen | ||
} | ||
`, | ||
}), | ||
).resolves.toMatchInlineSnapshot(` | ||
{ | ||
"data": { | ||
"registrationOpen": false, | ||
}, | ||
} | ||
`); | ||
|
||
await expect( | ||
execute({ | ||
query: /* GraphQL */ ` | ||
{ | ||
me { | ||
name | ||
} | ||
} | ||
`, | ||
}), | ||
).resolves.toMatchInlineSnapshot(` | ||
{ | ||
"data": null, | ||
"errors": [ | ||
{ | ||
"locations": [ | ||
{ | ||
"column": 11, | ||
"line": 3, | ||
}, | ||
], | ||
"message": "Insufficient permissions for selecting 'Query.me'.", | ||
}, | ||
{ | ||
"locations": [ | ||
{ | ||
"column": 13, | ||
"line": 4, | ||
}, | ||
], | ||
"message": "Insufficient permissions for selecting 'User.name'.", | ||
}, | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
it('should allow "me" when authenticated', async () => { | ||
const { execute } = await gateway({ | ||
supergraph: { | ||
with: 'mesh', | ||
services: [await service('users')], | ||
}, | ||
pipeLogs: 'gw.log', | ||
}); | ||
|
||
await expect( | ||
execute({ | ||
query: /* GraphQL */ ` | ||
{ | ||
registrationOpen | ||
me { | ||
name | ||
} | ||
} | ||
`, | ||
headers: { | ||
authorization: 'Bearer TOKEN', | ||
}, | ||
}), | ||
).resolves.toMatchInlineSnapshot(` | ||
{ | ||
"data": { | ||
"me": { | ||
"name": "John", | ||
}, | ||
"registrationOpen": false, | ||
}, | ||
} | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@e2e/operation-field-permissions", | ||
"private": true, | ||
"dependencies": { | ||
"@envelop/core": "^5.0.2", | ||
"@envelop/operation-field-permissions": "^6.0.0", | ||
"@graphql-mesh/compose-cli": "^1.2.13", | ||
"graphql": "^16.10.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { createServer } from 'http'; | ||
import { Opts } from '@internal/testing'; | ||
import { createSchema, createYoga } from 'graphql-yoga'; | ||
|
||
const opts = Opts(process.argv); | ||
|
||
createServer( | ||
createYoga({ | ||
maskedErrors: false, | ||
schema: createSchema<any>({ | ||
typeDefs: /* GraphQL */ ` | ||
type Query { | ||
registrationOpen: Boolean! | ||
me: User! | ||
} | ||
type User { | ||
name: String! | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
registrationOpen: () => false, | ||
me: () => ({ name: 'John' }), | ||
}, | ||
}, | ||
}), | ||
}), | ||
).listen(opts.getServicePort('users')); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.