-
Notifications
You must be signed in to change notification settings - Fork 73
refactor(core): decrease number of times model definitions are built #2057
refactor(core): decrease number of times model definitions are built #2057
Conversation
@@ -4,7 +4,8 @@ | |||
import { unlinkSync, existsSync } from 'fs'; | |||
import { buildSchema } from 'graphql'; | |||
import * as Knex from 'knex'; | |||
import { GraphbackDataProvider, GraphbackCoreMetadata, QueryFilter } from '@graphback/core'; | |||
import { GraphbackDataProvider, GraphbackPluginEngine, QueryFilter } from '@graphback/core'; | |||
import { SchemaCRUDPlugin } from '../../../graphback-codegen-schema/src'; |
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.
can we make graphback-codegen-schema
dev dependency and use that here instead of relative path?
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.
I tried importing the actual package, but got this error, which is isolated to the test files, not sure why it is happening
Type 'SchemaCRUDPlugin' is not assignable to type 'GraphbackPlugin'.
Types of property 'transformSchema' are incompatible.
Type '(metadata: import("/home/ephelan/code/aerogear/graphback/packages/graphback-runtime-knex/node_modules/@graphback/codegen-schema/node_modules/@graphback/core/types/plugin/GraphbackCoreMetadata").GraphbackCoreMetadata) => import("/home/ephelan/code/aerogear/graphback/node_modules/graphql/type/schema").GraphQLSchema' is not assignable to type '(metadata: import("/home/ephelan/code/aerogear/graphback/packages/graphback-core/types/plugin/GraphbackCoreMetadata").GraphbackCoreMetadata) => import("/home/ephelan/code/aerogear/graphback/node_modules/graphql/type/schema").GraphQLSchema'.
Types of parameters 'metadata' and 'metadata' are incompatible.
Type 'import("/home/ephelan/code/aerogear/graphback/packages/graphback-core/types/plugin/GraphbackCoreMetadata").GraphbackCoreMetadata' is not assignable to type 'import("/home/ephelan/code/aerogear/graphback/packages/graphback-runtime-knex/node_modules/@graphback/codegen-schema/node_modules/@graphback/core/types/plugin/GraphbackCoreMetadata").GraphbackCoreMetadata'.
Types have separate declarations of a private property 'supportedCrudMethods'.
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.
Ah I would not expect that error. Anyway, we can ignore this comments to not derail us from getting this in.
Maybe we can open a separate issue for this?
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.
Yeah, and when I added it as a devDependency I got a circular dependency warning, so that is possibly why:
lerna WARN ECYCLE @graphback/codegen-schema -> @graphback/core -> @graphback/codegen-schema
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.
Okay, that explains it.
import { migrateDB, removeNonSafeOperationsFilter } from 'graphql-migrations'; | ||
import { SQLiteKnexDBDataProvider } from '../../src/SQLiteKnexDBDataProvider'; | ||
import { SchemaCRUDPlugin } from '../../../graphback-codegen-schema'; |
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.
import { Context, createTestingContext } from "./__util__"; | ||
import { buildSchema } from 'graphql'; | ||
import { QueryFilter, GraphbackPluginEngine } from '@graphback/core'; | ||
import { SchemaCRUDPlugin } from '../../graphback-codegen-schema' |
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.
import { GraphbackCoreMetadata } from '@graphback/core'; | ||
import { SchemaCRUDPlugin } from "@graphback/codegen-schema"; | ||
import { GraphbackPluginEngine } from '@graphback/core'; | ||
import { SchemaCRUDPlugin } from "../../graphback-codegen-schema"; |
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.
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.
Really good change and goes in line with a similar improvement (cache models computation during plugin execution) I've had in my mind. Thanks for adding this. I've added some minor comments.
f9f8b22
to
98aaaaa
Compare
741fde6
to
5916e76
Compare
5916e76
to
959e2bc
Compare
Can we approve it but wait for the merge. If we release 1.0 in the coming days (early next week) it might be risky? Just curious if that is something that really needs to be done now considering 1.0 release etc. |
That is probably the wise choice @wtrocki - this looked to be a simple change but it is having some side effects. I will get it into a "ready" state but close it so we can restore it when ready. |
RelationshipBuilder blocking this from working fully:
#2023 will need to be completed before merging this. Closing for now. |
This splits the
models
metadata variable into a getter/setter to prevent building all models every time theGraphbackCoreMetadata#getModelDefinitions
is called.I ran benchmarks a few times and there is an improvement in startup time: