Skip to content
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

feat(@whook/example): add GraphQL server #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
6,463 changes: 1,897 additions & 4,566 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,16 @@ DEV_MODE=1
"@apidevtools/swagger-parser": "^10.1.0",
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^18.0.0",
"@whook/graphql": "^18.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": "^7.0.0",
"common-services": "^17.0.0",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.1",
"jwt-service": "^11.0.0",
"knifecycle": "^18.0.0",
Expand Down Expand Up @@ -436,13 +439,16 @@ DEV_MODE=1
"@apidevtools/swagger-parser": "^10.1.0",
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^18.0.0",
"@whook/graphql": "^18.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": "^7.0.0",
"common-services": "^17.0.0",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.1",
"jwt-service": "^11.0.0",
"knifecycle": "^18.0.0",
Expand Down Expand Up @@ -781,13 +787,16 @@ DEV_MODE=1
"@apidevtools/swagger-parser": "^10.1.0",
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^18.0.0",
"@whook/graphql": "^18.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": "^7.0.0",
"common-services": "^17.0.0",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.1",
"jwt-service": "^11.0.0",
"knifecycle": "^18.0.0",
Expand Down Expand Up @@ -1109,13 +1118,16 @@ DEV_MODE=1
"@apidevtools/swagger-parser": "^10.1.0",
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^18.0.0",
"@whook/graphql": "^18.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": "^7.0.0",
"common-services": "^17.0.0",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.1",
"jwt-service": "^11.0.0",
"knifecycle": "^18.0.0",
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(
outputFile.mock.calls.
find((call) => call[0].toString().endsWith('package.json'))?.[1]?.
toString() || ''
)
).toMatchInlineSnapshot(`
JSON.parse(
outputFile.mock.calls
.find((call) => call[0].toString().endsWith('package.json'))?.[1]
?.toString() || '',
),
).toMatchInlineSnapshot(`
{
"author": {
"email": "wayne@warner.com",
Expand All @@ -161,13 +161,16 @@ describe('initCreateWhook', () => {
"@apidevtools/swagger-parser": "^10.1.0",
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^18.0.0",
"@whook/graphql": "^18.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": "^7.0.0",
"common-services": "^17.0.0",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.1",
"jwt-service": "^11.0.0",
"knifecycle": "^18.0.0",
Expand Down Expand Up @@ -341,12 +344,12 @@ describe('initCreateWhook', () => {
await createWhook();

expect(
JSON.parse(
outputFile.mock.calls.
find((call) => call[0].toString().endsWith('package.json'))?.[1]?.
toString() || ''
)
).toMatchInlineSnapshot(`
JSON.parse(
outputFile.mock.calls
.find((call) => call[0].toString().endsWith('package.json'))?.[1]
?.toString() || '',
),
).toMatchInlineSnapshot(`
{
"author": {
"email": "wayne@warner.com",
Expand All @@ -356,13 +359,16 @@ describe('initCreateWhook', () => {
"@apidevtools/swagger-parser": "^10.1.0",
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^18.0.0",
"@whook/graphql": "^18.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": "^7.0.0",
"common-services": "^17.0.0",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.1",
"jwt-service": "^11.0.0",
"knifecycle": "^18.0.0",
Expand Down Expand Up @@ -521,12 +527,12 @@ describe('initCreateWhook', () => {
await createWhook();

expect(
JSON.parse(
outputFile.mock.calls.
find((call) => call[0].toString().endsWith('package.json'))?.[1]?.
toString() || ''
)
).toMatchInlineSnapshot(`
JSON.parse(
outputFile.mock.calls
.find((call) => call[0].toString().endsWith('package.json'))?.[1]
?.toString() || '',
),
).toMatchInlineSnapshot(`
{
"author": {
"email": "wayne@warner.com",
Expand All @@ -536,13 +542,16 @@ describe('initCreateWhook', () => {
"@apidevtools/swagger-parser": "^10.1.0",
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/graphiql": "^18.0.0",
"@whook/graphql": "^18.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": "^7.0.0",
"common-services": "^17.0.0",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.1",
"jwt-service": "^11.0.0",
"knifecycle": "^18.0.0",
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 @@ -81,13 +81,16 @@
"@apidevtools/swagger-parser": "^10.1.0",
"@whook/authorization": "^18.0.0",
"@whook/cors": "^18.0.0",
"@whook/graphiql": "^18.0.0",
"@whook/graphql": "^18.0.0",
"@whook/http-router": "^18.0.0",
"@whook/http-server": "^18.0.0",
"@whook/http-transaction": "^18.0.0",
"@whook/swagger-ui": "^18.0.0",
"@whook/whook": "^18.0.0",
"application-services": "^7.0.0",
"common-services": "^17.0.0",
"graphql-tag": "^2.12.6",
"http-auth-utils": "^6.0.1",
"jwt-service": "^11.0.0",
"knifecycle": "^18.0.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/whook-example/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ On air 🚀🌕
- 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 @@ -71,6 +71,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 environment
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;
25 changes: 25 additions & 0 deletions packages/whook-example/src/handlers/postGraphQL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
initPostGraphQL,
postGraphQLDefinition as baseDefinition,
} from '@whook/graphql';
import type { WhookAPIHandlerDefinition } from '@whook/whook';

// A trick to get Jest to work when having this message 🤷
// request for './handlers/getGraphQL.js' is not yet fulfilled
// import * as _ from './getGraphQL.js';

// 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
Loading