-
Notifications
You must be signed in to change notification settings - Fork 6
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
Added support to data version and execution metadata #64
Open
DoctorVoid
wants to merge
7
commits into
Enigmatis:master
Choose a base branch
from
DoctorVoid:backup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
18966f3
feat: return data version in extensions
DoctorVoid 98c8d59
Merge remote-tracking branch 'upstream/master' into backup
DoctorVoid aadfef0
feat: fix stuff
DoctorVoid a1d5864
feat: fix stuff
DoctorVoid f8b2470
feat: fix stuff
DoctorVoid c949614
feat: added model executor and data version mw
DoctorVoid 80e2724
fix: fix integration test
DoctorVoid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
import * as joi from 'joi'; | ||
|
||
const executionResultSchema = joi.object().keys({ | ||
result: joi.any(), | ||
executionMetadata: joi.any(), | ||
}); | ||
|
||
export function isExecutionResultResponse(candidate: object): boolean { | ||
if (!candidate) { | ||
return false; | ||
} | ||
return !joi.validate(candidate, executionResultSchema, { stripUnknown: true }).error; | ||
} |
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,19 @@ | ||
import { injectable } from 'inversify'; | ||
import { isExecutionResultResponse } from '../common/execution-result-validator'; | ||
import { Middleware, RequestMiddlewareParams, ResponseMiddlewareParams } from './middleware'; | ||
|
||
@injectable() | ||
export class ExecutionResultMiddleware implements Middleware { | ||
preResolve({ args }: RequestMiddlewareParams) { | ||
return; | ||
} | ||
|
||
postResolve(params: ResponseMiddlewareParams): any { | ||
if (isExecutionResultResponse(params.result)) { | ||
params.context.executionMetadata = params.result.executionMetadata; | ||
return params.result.result; | ||
} | ||
|
||
return params.result; | ||
} | ||
} |
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,18 @@ | ||
import { GraphQLExtension, GraphQLResponse } from 'graphql-extensions'; | ||
import { PolarisContext } from './polaris-context'; | ||
|
||
export class DataVersionExtension extends GraphQLExtension { | ||
willSendResponse(responseContext: { | ||
graphqlResponse: GraphQLResponse; | ||
context: PolarisContext; | ||
}) { | ||
const { context, graphqlResponse } = responseContext; | ||
if (context.body.operationName !== 'IntrospectionQuery') { | ||
graphqlResponse.extensions = { | ||
...graphqlResponse.extensions, | ||
dataVersion: context.executionMetadata && context.executionMetadata.dataVersion, | ||
}; | ||
} | ||
return responseContext; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { SoftDeleteConfiguration } from '@enigmatis/utills'; | ||
import { ExecutionMetadata, SoftDeleteConfiguration } from '@enigmatis/utills'; | ||
import { ApolloServer, Config, PubSub } from 'apollo-server-koa'; | ||
import { GraphQLError, GraphQLFormattedError, GraphQLSchema } from 'graphql'; | ||
import { applyMiddleware } from 'graphql-middleware'; | ||
|
@@ -16,6 +16,7 @@ import { Middleware } from '../middlewares/middleware'; | |
import { createMiddleware } from '../middlewares/polaris-middleware-creator'; | ||
import { PolarisProperties } from '../properties/polaris-properties'; | ||
import { RealitiesHolderValidator } from '../realities-holder/realities-holder-validator'; | ||
import { DataVersionExtension } from './data-version-extension'; | ||
import { IrrelevantEntitiesExtension } from './irrelevant-entities-extension'; | ||
import { PolarisContext } from './polaris-context'; | ||
|
||
|
@@ -62,6 +63,7 @@ export class PolarisGraphQLServer implements GraphQLServer { | |
extensions: [ | ||
() => new IrrelevantEntitiesExtension(), | ||
() => new ResponseHeadersExtension(), | ||
() => new DataVersionExtension(), | ||
], | ||
...userApolloConfig, | ||
}; | ||
|
@@ -83,9 +85,7 @@ export class PolarisGraphQLServer implements GraphQLServer { | |
`🚀 Server ready at http://localhost:${port}${this.server.graphqlPath}`, | ||
); | ||
this.polarisLogger.info( | ||
`🚀 Subscriptions ready at ws://localhost:${port}${ | ||
this.server.subscriptionsPath | ||
}`, | ||
`🚀 Subscriptions ready at ws://localhost:${port}${this.server.subscriptionsPath}`, | ||
); | ||
resolve(); | ||
}); | ||
|
@@ -148,6 +148,7 @@ export class PolarisGraphQLServer implements GraphQLServer { | |
headers, | ||
body: ctx.request.body, | ||
softDeleteConfiguration: this.softDeleteConfiguration, | ||
executionMetadata: { debugDate: new Date() }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove debug date |
||
irrelevantEntities: new IrrelevantEntitiesContainer(), | ||
...this.getCustomContext(ctx), | ||
}; | ||
|
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you checking the operation name?