Skip to content

Commit

Permalink
feat(@whook/example): add GraphQL server
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Feb 27, 2024
1 parent 4600433 commit 518004a
Show file tree
Hide file tree
Showing 14 changed files with 2,427 additions and 4,486 deletions.
6,367 changes: 1,907 additions & 4,460 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,16 @@ DEV_MODE=1
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^15.0.0",
"@whook/graphql": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"application-services": "^6.0.0",
"common-services": "^16.0.1",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.0",
"jwt-service": "^10.0.4",
"knifecycle": "^17.0.1",
Expand Down Expand Up @@ -478,13 +481,16 @@ DEV_MODE=1
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^15.0.0",
"@whook/graphql": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"application-services": "^6.0.0",
"common-services": "^16.0.1",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.0",
"jwt-service": "^10.0.4",
"knifecycle": "^17.0.1",
Expand Down Expand Up @@ -850,13 +856,16 @@ DEV_MODE=1
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^15.0.0",
"@whook/graphql": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"application-services": "^6.0.0",
"common-services": "^16.0.1",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.0",
"jwt-service": "^10.0.4",
"knifecycle": "^17.0.1",
Expand Down Expand Up @@ -1205,13 +1214,16 @@ DEV_MODE=1
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^15.0.0",
"@whook/graphql": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"application-services": "^6.0.0",
"common-services": "^16.0.1",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.0",
"jwt-service": "^10.0.4",
"knifecycle": "^17.0.1",
Expand Down
45 changes: 27 additions & 18 deletions packages/whook-create/src/services/createWhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ describe('initCreateWhook', () => {
await createWhook();

expect(
JSON.parse(
writeFile.mock.calls
.find((call) => call[0].toString().endsWith('package.json'))?.[1]
?.toString() || '',
),
).toMatchInlineSnapshot(`
JSON.parse(
writeFile.mock.calls.
find((call) => call[0].toString().endsWith('package.json'))?.[1]?.
toString() || ''
)
).toMatchInlineSnapshot(`
{
"author": {
"email": "[email protected]",
Expand All @@ -160,13 +160,16 @@ describe('initCreateWhook', () => {
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^15.0.0",
"@whook/graphql": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"application-services": "^6.0.0",
"common-services": "^16.0.1",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.0",
"jwt-service": "^10.0.4",
"knifecycle": "^17.0.1",
Expand Down Expand Up @@ -368,12 +371,12 @@ describe('initCreateWhook', () => {
await createWhook();

expect(
JSON.parse(
writeFile.mock.calls
.find((call) => call[0].toString().endsWith('package.json'))?.[1]
?.toString() || '',
),
).toMatchInlineSnapshot(`
JSON.parse(
writeFile.mock.calls.
find((call) => call[0].toString().endsWith('package.json'))?.[1]?.
toString() || ''
)
).toMatchInlineSnapshot(`
{
"author": {
"email": "[email protected]",
Expand All @@ -382,13 +385,16 @@ describe('initCreateWhook', () => {
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^15.0.0",
"@whook/graphql": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"application-services": "^6.0.0",
"common-services": "^16.0.1",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.0",
"jwt-service": "^10.0.4",
"knifecycle": "^17.0.1",
Expand Down Expand Up @@ -575,12 +581,12 @@ describe('initCreateWhook', () => {
await createWhook();

expect(
JSON.parse(
writeFile.mock.calls
.find((call) => call[0].toString().endsWith('package.json'))?.[1]
?.toString() || '',
),
).toMatchInlineSnapshot(`
JSON.parse(
writeFile.mock.calls.
find((call) => call[0].toString().endsWith('package.json'))?.[1]?.
toString() || ''
)
).toMatchInlineSnapshot(`
{
"author": {
"email": "[email protected]",
Expand All @@ -589,13 +595,16 @@ describe('initCreateWhook', () => {
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^15.0.0",
"@whook/graphql": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
"@whook/swagger-ui": "<current_version>",
"@whook/whook": "<current_version>",
"application-services": "^6.0.0",
"common-services": "^16.0.1",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.0",
"jwt-service": "^10.0.4",
"knifecycle": "^17.0.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/whook-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@
"dependencies": {
"@whook/authorization": "^15.0.0",
"@whook/cors": "^15.0.0",
"@whook/graphiql": "^15.0.0",
"@whook/graphql": "^15.0.0",
"@whook/http-router": "^15.0.0",
"@whook/http-server": "^15.0.0",
"@whook/http-transaction": "^15.0.0",
"@whook/swagger-ui": "^15.0.0",
"@whook/whook": "^15.0.0",
"application-services": "^6.0.0",
"common-services": "^16.0.1",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.0",
"jwt-service": "^10.0.4",
"knifecycle": "^17.0.1",
Expand Down
9 changes: 6 additions & 3 deletions packages/whook-example/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ describe('commands should work', () => {
);

expect({
stdout: stdout.replace(/( |"|')([^ ]+)\/whook\//g, ' /whook/'),
stderr: stderr.replace(/( |"|')([^ ]+)\/whook\//g, ' /whook/'),
}).toMatchInlineSnapshot(`
stdout: stdout.replace(/( |"|')([^ ]+)\/whook\//g, ' /whook/'),
stderr: stderr.replace(/( |"|')([^ ]+)\/whook\//g, ' /whook/')
}).toMatchInlineSnapshot(`
{
"stderr": "⚡ - Loading configurations from /whook/packages/whook-example/dist/config/local/config.js".
",
Expand All @@ -32,6 +32,9 @@ describe('commands should work', () => {
- ls: Print available commands
# Provided by "@whook/graphql": none
# Provided by "@whook/cors": none
Expand Down
4 changes: 4 additions & 0 deletions packages/whook-example/src/config/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ const CONFIG: Omit<AppConfig, 'HOST'> = {
...DEFAULT_SWAGGER_UI_CONFIG,
defaultModelRendering: 'model',
},
GRAPHIQL: {
path: '/graphiql',
defaultQuery: '{ hello }',
},
};

export default CONFIG;
1 change: 1 addition & 0 deletions packages/whook-example/src/config/local/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Finally the configuration file for a given environnment
const CONFIG: AppConfig = {
...COMMON_CONFIG,
HOST: 'localhost',
DEV_ACCESS_MECHANISM: 'Fake',
DEV_ACCESS_TOKEN: 'admin|1|1',
DEFAULT_MECHANISM: 'Fake',
OPEN_API_TYPES_CONFIG: {
Expand Down
21 changes: 21 additions & 0 deletions packages/whook-example/src/handlers/getGraphQL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
initGetGraphQL,
getGraphQLDefinition as baseDefinition,
} from '@whook/graphql';
import type { WhookAPIHandlerDefinition } from '@whook/whook';

// Add authentication to the base getGraphQL endpoints that
// would otherwise be public per default
export const definition: WhookAPIHandlerDefinition = {
...baseDefinition,
operation: {
...baseDefinition.operation,
security: [
{
bearerAuth: ['admin'],
},
],
},
};

export default initGetGraphQL;
21 changes: 21 additions & 0 deletions packages/whook-example/src/handlers/postGraphQL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
initPostGraphQL,
postGraphQLDefinition as baseDefinition,
} from '@whook/graphql';
import type { WhookAPIHandlerDefinition } from '@whook/whook';

// Add authentication to the base postGraphQL endpoints that
// would otherwise be public per default
export const definition: WhookAPIHandlerDefinition = {
...baseDefinition,
operation: {
...baseDefinition.operation,
security: [
{
bearerAuth: ['admin'],
},
],
},
};

export default initPostGraphQL;
Loading

0 comments on commit 518004a

Please sign in to comment.