-
-
Notifications
You must be signed in to change notification settings - Fork 816
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
Schema transforms #1463
Merged
Merged
Schema transforms #1463
Conversation
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
schema transform functions take a schema as an argument and return a schema, possibly modifying it a schema transform function can be templated, i.e. one can create a function that takes certain arguments, such as the names of directives that annotate fields of interest, and return a schema transform function that modifies the schema based on the specified annotating directives this allows one to reuse a schema transform function across projects, allowing for the customization of the schema transform function on a per use basis schema transform functionc can be called directly on a schema to modify it before use -- makeExecutableSchema can now also be passed an array of schema transform functions, with makeExecutableSchema responsible for performing all schema transformations prior to returning. Eventually, all schema visitor examples can be rewritten using the schema transform functional API addresses #1234
…ing of all fields and input fields
include deprecated example in tests reorder some types
ardatan
approved these changes
May 12, 2020
This was referenced May 13, 2020
ardatan
added a commit
that referenced
this pull request
May 21, 2020
* Move graphql-toolkit and switch to monorepo * Update README * Remove inspector * Add yarn.lock back * Add yarn.lock back * Rename packages * Update eslint config * Seperate mocking * Update docs * Update npm badge * Make highlight images smaller * Update yarn.lock * Move casual to mocking's devDeps * Remove link from warning * Seperate schema upload stuff * Fix stuff * Drop support for older versions * Update eslint * Add dateformat typings * Use async spawn * Promisify child spawn * Use introspectSchema in url-loader * Fix typings * Fix renovate badge * Improve release.js * Seperate generator and stitching * Fix deps * Fix deps * Add ardatan/graphql-toolkit#578 * Remove deepmerge and use mergeDeep from utils * Remove aggregate-error dependency * refactor(stitchSchemas): add support of all makeExecutableSchema options (#1424) * refactor(stitchSchemas): to cover all makeExecutableSchema options * run prettier * drop parse() and parseLiteral() * unstaged! Co-authored-by: Arda TANRIKULU <[email protected]> * Move specific types back to their own packages * Split schema-wrapping and schema-stitching (#1429) * second attempt * commit * fix? * fix * Improve deps Co-authored-by: Arda TANRIKULU <[email protected]> * shorter names * Update simple-git * rename stitching-upload to links (#1432) * Remove unnecessary prepack script and use new Node * Do tests for multiple graphql versions * Do not use fsExtra in match-graphql.js * Use same yarn cache * Ensure different node versions use different cache * Use different cache for each graphql and node versions * Use fs-extra * remove unused type, was used with updateEachKey * move SchemaLikeObject to stitching package type functions as type alias for all the things that can be passed to stitchSchemas 'schemas' parameter * Split and refactor graphql import (#1437) * Split & Refactor GraphQL Import * fIX * export toConfig functions not available in graphql-js (#1433) * export toConfig functions not available in graphql-js * avoid type,toConfig() workaround now that fieldToFieldConfig available additional benefit of fieldToFieldConfig is that rootFieldTransformer and fieldTransform argumenst in TransformRootFields and TransformObjectFields expect functions that convert fields to fieldConfig, so now end users can easily create their own functions * Fix imports * Fix package.json * Fix integration tests * remove orphaned type * refactor resolver types and streamline related functions (#1441) * refactor resolver types and streamline related functions = adds back ability to set enum type properties using double underscore convention, was present in v4. = also removes functional resolvers from stitchSchemas, not necessary as mergeInfo exposed on info = removes info.mergeInfo.delegate and info.mergeInfo.delegateToSchema = removed object filter for resolvers map, non-objects should not be present. * move fragment and selectionSet hints to stitch types package using declaration merging * add tests demonstrating fix for 1434 Use inheritResolversFromInterfaces and use the interface to set a selectionSet hint * move package-specific types out of utils * replace fragment hints with selectionSet hints selectionSet hints are less verbose and allow extension from interfaces * Fix build * Seperate test build and lint * Improve github workflows * Update workflow names * Fix stitching from and to interfaces (#1443) * ExpandAbstractTypes to check transformed subschema An abstract type may be present in the target schema, but renamed. ExpandAbstractTypes expands the abstract types not present in the target schema, but it should check the transformed target schema, to not be misled by renaming. This may require manually passing the transformed schema in some cases. The default can stay to assume no renaming. Within stitched schemas, the correct transformed schema can be saved to and then read from info.mergeInfo.transformedSchema. * move ICreateRequest to delegate package with ICreateRequestFromInfo * Add WrapConcreteTypes transform = fixes #751 * allow redelegation of nested root query fields in some circumstances nested root fields may not always successfully stitch to subschemas, for example when the root field is a new abstract field stitching to a concrete field or the reverse * provide transformedSchema argument in more instances = changes CreateResolverFn signature to take an options argument of type ICreateResolverOptions * add mapSchemaByField (#1447) mapSchemaByField is a version of forEachField that does not mutate original schema * Use field configs (#1451) * remove spurious uses of fieldToFieldConfig If type.toConfig() is later called returning config, fieldToFieldConfig is called every field to populate config.fields, so no need to call it individually from the field map, might as well just move the toConfig call earlier. * remove need for fieldToFieldConfig function BREAKING CHANGE: transformer functions will be passed field config objects instead of field objects. fieldToFieldConfig was necessary because TransformRootField et al functions expected users to pass a function that receives a field and returns a field config, modified as desired. This can be made easier for end users by simply passing the transformer function a field config instead of a field, obviating the need for fieldToFieldConfig. * replace mapSchemaByField with more MapperKind options within mapSchema * hoist schema transformation out of type/field loop this should be performed only once! * don't mutate previous schemas with HoistField and WrapFields transforms fields helper functions now take a schema and return a new schema, rather than mutating the original schema's typemap. part of broader push throughout the code base to avoid mutating schemas Note: specifically within the context of transforms, we are currently protected against any side effects when mutating the passed in schema in any case. cloneSchema is used during the transformation loop -- the original schema cannot be mutated by a transformation, because a clone is passed rather than the original. Nevertheless, these changes are part of the overall effort to never rely on the ability to mutate an existing graphql schema. * remove use of createNamedStub and add comment to explain how this works * bring back TypeMap * update lock file * use improved mapSchema to make schema package functions not modify existing schema (#1456) * refactor WrapFields = add enhanceSchema function that can add/replace types/directives, see detailed comment with regard to motivation even for simply adding a new type (vs just using toConfig) = simplify field helper functions more complex modifyFields function is not necessary, empty types can be added and later extended so if multiples types with cross-referencing fields need to be added, the types can be added first without fields, and the fields appended later. = appendFields currently adds fields to a new type if no existing type is found, this functionality perhaps should be made configurable or put in a separate function * convert default values as leaf values internal values may change when mapping this is necessary to eventually replace use of healSchema and forEachDefaultValue within AddResolversToSchema, although use of mapSchema will require that function to be immutable * use TypeMap type * rename functions = appendObjectFields and removeObjectFields better describe that these functions only apply to fields of GraphQLObjectType = enhanceSchema is a bit vague * fix mapSchema typo All input types mapped to input object types! * continue mutable => immutable conversion This change: = bring default value updating into mapSchema = change aaddResolversToSchema, addCatchUndefinedToSchema, addErrorLoggingToSchema, addSchemaLevelResolver to all use mapSchema to return a new schema without modifying the passed in schema = change all internal use of these functions and all tests to use the return value = pass typeName instead of a type to field mappers, as passing a type can be confusing, because the type may be in the process of being mapped and not equivalent to the type in the original schema ** the visitSchema function and the schema directive classes that use visitSchema are the next (final?) target for mutable => immutable conversion * fix more docs * prune unnecessary field mapper types there are only really two types of fields, "composite fields" or "output fields" called "fields" in graphql-js on object and interfaces, and input fields on input objects. The generic FieldMapper type is useful for internal function mapFields so that field mapping logic does not have to be duplicated between output and input fields because of the different types. * Update contact link * Schema transforms (#1463) * rewrite attachDirectiveResolvers to be immutable * add mapping by arguments * add schema transforms schema transform functions take a schema as an argument and return a schema, possibly modifying it a schema transform function can be templated, i.e. one can create a function that takes certain arguments, such as the names of directives that annotate fields of interest, and return a schema transform function that modifies the schema based on the specified annotating directives this allows one to reuse a schema transform function across projects, allowing for the customization of the schema transform function on a per use basis schema transform functionc can be called directly on a schema to modify it before use -- makeExecutableSchema can now also be passed an array of schema transform functions, with makeExecutableSchema responsible for performing all schema transformations prior to returning. Eventually, all schema visitor examples can be rewritten using the schema transform functional API addresses #1234 * add generic field mapper to SchemaMapper to allow indiscriminate mapping of all fields and input fields * add enum directive extraction and value mapping * add tests demonstrating templated schema transforms * update docs for schemaTransforms include deprecated example in tests reorder some types * Fix absolute imports (#1470) * restore v4 healSchema functionality (#1468) Within v4, schema healing was less agressive and did not attempt to refresh the schemas private variables and correct the root types. Reversion to the less agressive healSchema makes some sense. Library users require healSchema because they are modifying the schema in place using visitSchema or visitSchemaDirectives. This lets them do some things that perhaps they shouldn't (e.g. create fields of different types with identical names), but it is unexpected for the more aggressive healing to actually fail where the less agressive healing works fine. See #1462 This requires a rewrite of the existing Gatsby transforms which rely on the more aggressive healSchema within v5, but this is recommended in any case, as healSchema/visitSchema/visitSchemaDirectives are all now considered legacy in any case. Instructions for do-it-yourself more aggressive healing are included within comments within the healSchema, which detail the deficiencies of the less aggressive approach rather than releasing the more aggressive healing functionality under an option or new function name. This is because library users are now encourages to not modify existing schemas in place using visitSchema/visitSchemaDirectives, and to instead use mapSchema. * fix latest test (#1471) compare original error as comparing GraphQL errors is trickier * use static types (#1472) * 6.0.0-alpha.1 * fix removeObjectFields helper (#1480) it was selecting, not helping! it turns out that removing all object fields leads to automatic type pruning -- this could be optionally disabled, but easier for users to just add a selectObjectFields helper and a modifyObjectFields helper that can remove and add fields in a single step * Fix bare request delegation (#1479) * add failing test also moves delegation test to delegate package * fix bare delegation * drop requirement for info with bare delegation * add explicit fieldNodes bare delegation test * further improve bare delegation (#1482) handle object fields handle some errors * simplify handleNull (#1483) this function after prior refactoring was recursively passing along arugments without actually ever using them * remove dead argument to unwrapResult (#1484) * fixes * Some improvements on deps * Fix not printing some directive definitions ardatan/graphql-toolkit#611 * Stitching info (#1490) * remove dead type * rename mergeInfo to stitchingInfo stash on extensions instead of annotating info argument closes #1486 * make generic transforms generic (#1495) closes #1485 * move StitchingInfo type to both delegate and stitch in theory, the packages mutually depend on each other, but really they just both depend on the StitchingInfo type the fragments field on StitchingInfo was deprecated when we switched to precompiling fragments/selectionSets i.e. when we switched from using ReplaceFieldWithFragment to AddReplacementFragments/AddReplacementSelectionSets * prepackage mergedTypesSelectionSets into its own map on stitchingInfo = removes need for further ".selectionSet" indexing within AddMergedTypeSelectionSets = allows AddMergedTypeSelectionSets to be more generic, can accept a map of type names and any selection set * Rename transforms to generic names because they are actually more generic than they appear. AddReplacementFragments => AddFragmentsByFields AddReplacementSelectionSets => AddSelectionSetsByField AddMergedTypeSelectionSets => AddSelectionSetsByType ReplaceFIeldWithFragment is for raw string fragments, retaining old name even though it doesn't replace anything just to smooth backwards compatibility * Update match-graphql.js * Update typescript-eslint monorepo to v2.34.0 (#1502) Co-authored-by: Renovate Bot <[email protected]> * Trigger CI for this branch * Fix workflow * avoid infinite loop (#1505) fixSchemaAst fixes the schema ast by adding a getter for the property which lazily calls buildSchema(printSchemaWithDirectives(schema) to rebuild the schema. printSchemaWithDirectives, however, now checks to see if schema.astNode is defined, and so will end up calling itself. This can be avoided by making sure that the astNode is not defined as a getter. fixSchemaAst could alternatively be changed to return a new schema ratehr than modifying the original schema. * Update dependency simple-git to v2.5.0 (#1500) Co-authored-by: Renovate Bot <[email protected]> * Pin dependency graphql-upload to 10.0.0 (#1491) Co-authored-by: Renovate Bot <[email protected]> * Update dependency @types/jest to v25.2.3 (#1492) Co-authored-by: Renovate Bot <[email protected]> * Fix ts error * Update dependency typescript to v3.9.2 (#1501) Co-authored-by: Renovate Bot <[email protected]> * Update dependency lint-staged to v10.2.4 (#1498) Co-authored-by: Renovate Bot <[email protected]> * Update dependency apollo-server-express to v2.13.1 (#1497) Co-authored-by: Renovate Bot <[email protected]> * Update dependency @types/node to v13.13.6 (#1494) Co-authored-by: Renovate Bot <[email protected]> * Update dependency @types/lodash to v4.14.151 (#1493) Co-authored-by: Renovate Bot <[email protected]> * Update dependency @types/supertest to v2.0.9 (#1496) Co-authored-by: Renovate Bot <[email protected]> * v6.0.0-alpha.2 * guard against undefined directives (#1506) in --some-- codebase locations! closes #1486 * Update dependency @docusaurus/core to v2.0.0-alpha.55 (#1507) Co-authored-by: Renovate Bot <[email protected]> * Update dependency @types/fs-extra to v9.0.1 (#1510) Co-authored-by: Renovate Bot <[email protected]> * Update dependency @types/node to v13.13.7 (#1511) Co-authored-by: Renovate Bot <[email protected]> * Update dependency @types/lodash to v4.14.152 (#1512) Co-authored-by: Renovate Bot <[email protected]> * Update dependency @types/node to v13.13.8 (#1514) Co-authored-by: Renovate Bot <[email protected]> * Update dependency typescript to v3.9.3 (#1515) Co-authored-by: Renovate Bot <[email protected]> * support regenerating schema, type and directive object annotations (#1517) within the graphql ecosystem, many users still annotate schemas, types, and possibly directives with custom properties instead of using the newer extensions property. mapSchema should copy all custom properties when creating graphql objects as possible. * provide option to update schema in place (#1518) for full backwards compatibility reverts changes with respect to type annotation -- if types have already been modified in place, more straightforward to just keep doing so * Use Bob v1.0.0 (#1519) * Add graphql-tools that reexports all other packages * Fix naming collision * Update dependency bob-the-bundler to v1.0.1 (#1520) Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Yaacov Rydzinski <[email protected]> Co-authored-by: Kamil Kisiela <[email protected]> Co-authored-by: Dotan Simha <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Renovate Bot <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
new implementation of directive-based schema transformation
closes #1234