Skip to content

Conversation

@darrellwarde
Copy link
Contributor

Description

If possible, instantiate connection to JWKS on startup. I was informed that caching was not working between requests, and this was because we were instantiating a new JWKS connection on every request.

This PR, where it can, creates a single connection on startup.

NOTE: Subscriptions are a hot mess ("bearerToken" stuff) - this needs fixing on 4.0.0 where we have better context typings. The context there needs looking at.

Complexity

Complexity: Low

@changeset-bot
Copy link

changeset-bot bot commented Aug 15, 2023

🦋 Changeset detected

Latest commit: a0e6346

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@neo4j/graphql Patch
@neo4j/graphql-toolbox Patch
@neo4j/graphql-ogm Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@neo4j-team-graphql
Copy link
Collaborator

neo4j-team-graphql commented Aug 15, 2023

Thanks for the Neo4j GraphQL Toolbox updates.

The Neo4j GraphQL Toolbox has now been torn down - reopening this PR will republish it.

@neo4j-team-graphql
Copy link
Collaborator

neo4j-team-graphql commented Aug 15, 2023

Performance Report

No Performance Changes

Show Full Table
name dbHits old dbHits time (ms) old time (ms) maxRows
aggregations.TopLevelAggregate 3403 3403 34 52 1134
aggregations.NestedAggregation 16553 16553 70 87 2174
aggregations.AggregationWithWhere 11979 11979 45 53 2174
aggregations.AggregationWhereWithinNestedRelationships 22116987 22116987 3402 3135 2008534
aggregations.AggregationWhereWithinNestedConnections 22116987 22116987 3049 2815 2008534
aggregations.NestedCountFromMovieToActors 9734 9734 43 54 2174
aggregations.NestedCountFromActorsToMovie 9937 9937 47 71 2174
aggregations.DeeplyNestedCount 13070331 13070331 4457 4120 2008534
batch-create.BatchCreate 4200 4200 140 155 600
batch-create.BatchCreateSmall 77 77 61 112 11
connect.createAndConnect 14424 14424 150 244 3003
connections.Connection 14082 14082 76 68 2174
connections.NestedConnection 45470 45472 106 144 4516
connections.ConnectionWithSort 3284 3284 69 82 1040
connections.ConnectionWithSortAndCypher 3284 3284 186 391 1040
create.SimpleMutation 7 7 79 138 1
cypher-directive.TopLevelCypherDirective 122100 122100 663 728 12241
cypher-directive.TopLevelCypherDirectiveWithColumnName 153617 153617 184 216 12241
delete.SimpleDelete 19401 19401 261 248 1040
delete.NestedDeleteInUpdate 23202 23202 158 321 2040
2925.SingleRelationshipFilter 6468 6468 85 49 1040
2925.NestedSingleRelationshipFilter 22900 22900 87 124 2174
2925.SingleRelationshipRequiredFilter 5201 5201 39 51 1040
2925.NestedSingleRelationshipRequiredFilter 9361 9361 60 86 1040
query.SimpleQuery 3121 3121 22 26 1040
query.SimpleQueryWithRelationship 16162 16162 64 53 2174
query.QueryWhere 9718 9696 46 46 2168
query.SimpleQueryWithNestedWhere 9896 9874 66 65 2168
query.Nested 10096041 10096041 10110 10359 2008534
query.NestedWithFilter 10074401 10074401 9964 10052 2004000
query.OrFilterOnRelationships 43072 42029 193 226 1994
query.OrFilterOnRelationshipsAndNested 36968 34894 272 335 1994
query.QueryWithNestedIn 13377 13515 57 104 1209
query.NestedConnectionWhere 9834 9834 61 168 2174
query.DeeplyNestedConnectionWhere 9946 9974 83 139 2174
query.DeeplyNestedWithRelationshipFilters 19218 19230 142 214 1620
query.NestedWithRelationshipSingleFilters 3881 3881 199 336 1134
query.Fulltext 80 80 67 77 16
query.FulltextWithNestedQuery 587 587 81 100 84
sorting.SortMultipleTypes 3515 3515 126 132 1040
sorting.SortMultipleTypesWithCypherWithCypher 1505 1493 223 275 1040
sorting.SortOnNestedFields 14082 14082 64 57 2174
sorting.SortDeeplyNestedFields 43198 43198 99 107 4516
sorting.SortWithTopLevelCypher 3121 3121 56 71 1040
unions.SimpleUnionQuery 321 321 67 72 35
unions.SimpleUnionQueryWithMissingFields 293 293 65 81 35
unions.NestedUnion 410637 410637 333 322 33033
unions.NestedUnionWithMissingFields 384611 384611 293 312 33033
update.NestedUpdate 16143 16143 112 130 2002

Old Schema Generation: 39.834s
Schema Generation: 40.189s
Old Subgraph Schema Generation: 48.469s
Subgraph Schema Generation: 49.639s

Comment on lines +117 to +124
if (secret instanceof Uint8Array) {
debug("Verifying JWT using secret");
const { payload } = await jwtVerify(token, secret, this.authorization.verifyOptions);
return payload;
}
debug("Verifying JWKS using url");
const { payload } = await jwtVerify(token, secret, this.authorization.verifyOptions);
return payload;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are now the same. Is there any reason for the if-else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, believe it or not, TypeScript gives an error if you don't do it like this - I don't know if there's a way to resolve this without @ts-ignore.

return payload;
}

private async verifyBearerToken(token: string, secret: Key): Promise<JWTPayload> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify was changed to receive the resolvedKey all the time, but verifyBearerToken was not. Is there a reason for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually mirrors the previous behaviour - keys were not resolved via callback for Subscriptions. I want to change this in 4.0.0 where we have the better context typings - it's almost too difficult here.

@darrellwarde darrellwarde merged commit 9354860 into neo4j:dev Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants