-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: already generated TC may be obtained via schemaComposer.getTC(m…
…ongooseSchema) Removed old logic, where generated schemas stored in the mongoose object `model.schema._gqcTypeComposer`. Related: #26 (comment)
- Loading branch information
Showing
18 changed files
with
25 additions
and
35 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ type ComposeScalarType = string | GraphQLScalarType; | |
type ComposeOutputType = TypeComposer | ComposeScalarType | EnumTypeComposer | [ComposeOutputType]; | ||
|
||
export type MongoosePseudoModelT = { | ||
_gqcTypeComposer?: TypeComposer, | ||
schema: Schema<any>, | ||
}; | ||
|
||
|
@@ -117,19 +116,21 @@ export function convertModelToGraphQL( | |
): TypeComposer { | ||
const schemaComposer = sc || globalSchemaComposer; | ||
|
||
// if model already has generated TypeComposer early, then return it | ||
const modelSchema: any = model.schema; | ||
if (modelSchema && modelSchema._gqcTypeComposer) { | ||
return modelSchema._gqcTypeComposer; | ||
} | ||
|
||
if (!typeName) { | ||
throw new Error('You provide empty name for type. `name` argument should be non-empty string.'); | ||
} | ||
|
||
const typeComposer = schemaComposer.getOrCreateTC(typeName); | ||
// if model already has generated TypeComposer early, then return it | ||
// $FlowFixMe await landing [email protected] or above | ||
if (schemaComposer.has(model.schema)) { | ||
// $FlowFixMe await landing [email protected] or above | ||
return schemaComposer.getTC(model.schema); | ||
} | ||
|
||
modelSchema._gqcTypeComposer = typeComposer; // eslint-disable-line no-param-reassign | ||
const typeComposer = schemaComposer.getOrCreateTC(typeName); | ||
// $FlowFixMe await landing [email protected] or above | ||
schemaComposer.set(model.schema, typeComposer); | ||
schemaComposer.set(typeName, typeComposer); | ||
|
||
const mongooseFields = getFieldsFromModel(model); | ||
const graphqlFields = {}; | ||
|
@@ -161,7 +162,7 @@ export function convertModelToGraphQL( | |
} | ||
|
||
export function convertSchemaToGraphQL( | ||
schema: Object, // MongooseModelSchemaT, TODO use Model from mongoose_v4.x.x definition when it will be public | ||
schema: Schema<any>, | ||
typeName: string, | ||
sc?: SchemaComposer<any> | ||
): TypeComposer { | ||
|
@@ -171,15 +172,18 @@ export function convertSchemaToGraphQL( | |
throw new Error('You provide empty name for type. `name` argument should be non-empty string.'); | ||
} | ||
|
||
if (schema._gqcTypeComposer) { | ||
return schema._gqcTypeComposer; | ||
// $FlowFixMe await landing [email protected] or above | ||
if (schemaComposer.has(schema)) { | ||
// $FlowFixMe await landing [email protected] or above | ||
return schemaComposer.getTC(schema); | ||
} | ||
|
||
const tc = convertModelToGraphQL({ schema }, typeName, schemaComposer); | ||
// also generate InputType | ||
tc.getInputTypeComposer(); | ||
|
||
schema._gqcTypeComposer = tc; // eslint-disable-line | ||
// $FlowFixMe await landing [email protected] or above | ||
schemaComposer.set(schema, tc); | ||
return tc; | ||
} | ||
|
||
|
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
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