You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This release is only compatible with TypeORM v0.3.0 and newer. Support for TypeORM v0.2.x is dropped (but you can keep using typeorm-graphql-joiner@^1).
TypeORM v0.3.0 changed the way relations and data sources work. The relations option to findX() methods now expects an object instead of an array of strings (the array format is deprecated and will be removed in v0.4.0).
This has necessitated significant changes in this release to support the new object format. A relations object now looks like:
Renamed RelationMapper class to GraphRelationBuilder
Renamed method buildRelationListForQuery to buildForQuery
Renamed method buildRelationList to build
Migration Guide
If you were using typeorm-graphql-joiner with TypeORM v0.2.x before, and you're upgrading to TypeORM v0.3.x, you'll need to do the following:
Remove dependency typeorm-graphql-joiner in your package.json
Add dependency typeorm-relations-graphql in your package.json
Replace code like:
// OLD WAYimport{RelationMapper}from'typeorm-graphql-joiner';constrelationMapper=newRelationMapper(connection);
with:
// NEW WAYimport{GraphRelationBuilder}from'typeorm-relations-graphql';constgraphRelationBuilder=newGraphRelationBuilder(dataSource);
Replace code like:
// OLD WAYconstrelations=relationMapper.buildRelationListForQuery(Product,info);awaitproductRepository.find({relations: [...relations]});
with:
// NEW WAYconstrelationMap=graphRelationBuilder.buildForQuery(Product,info);awaitproductRepository.find({relations: relationMap.toFindOptionsRelations()});
If you were using relationMapper.isFieldSelected() before, add graphql-info-inspector to your dependencies and use it like this:
// NEW WAYimport{isFieldSelected}from'graphql-info-inspector';// In a Product resolver, for example:if(isFieldSelected('image.tags',info)){// Client wants `product { image { tags { ... }}}`}
If you need to manipulate the relations after mapping what's selected by the GraphQL query (for example, when there are relations that you always want to fetch for other reasons), previously you could just modify the resulting Set or Array of strings but now things are a little more complicated. However GraphRelationBuilder returns a RelationMap instance which makes this easy: 🔥
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
What's Changed
typeorm-graphql-joinerto 📦 typeorm-relations-graphqlFull Changelog: v1.0.2...v2.0.0
This release is only compatible with TypeORM v0.3.0 and newer. Support for TypeORM v0.2.x is dropped (but you can keep using
typeorm-graphql-joiner@^1
).TypeORM v0.3.0 changed the way relations and data sources work. The
relations
option tofindX()
methods now expects an object instead of an array of strings (the array format is deprecated and will be removed in v0.4.0).This has necessitated significant changes in this release to support the new object format. A relations object now looks like:
The library has been reworked to produce that kind of object, and to work with a TypeORM
DataSource
rather than a legacy TypeORMConnection
. 🔌A number of other changes and improvements have also been made:
GraphQLResolveInfo
into a separate package, 📦 graphql-info-inspectorrelations
objecttypeorm-graphql-joinerto 📦 typeorm-relations-graphqlRelationMapper
class toGraphRelationBuilder
buildRelationListForQuery
tobuildForQuery
buildRelationList
tobuild
Migration Guide
If you were using
typeorm-graphql-joiner
with TypeORM v0.2.x before, and you're upgrading to TypeORM v0.3.x, you'll need to do the following:Remove dependency
typeorm-graphql-joiner
in your package.jsonAdd dependency
typeorm-relations-graphql
in your package.jsonReplace code like:
with:
Replace code like:
with:
If you were using
relationMapper.isFieldSelected()
before, addgraphql-info-inspector
to your dependencies and use it like this:If you need to manipulate the relations after mapping what's selected by the GraphQL query (for example, when there are relations that you always want to fetch for other reasons), previously you could just modify the resulting
Set
orArray
of strings but now things are a little more complicated. HoweverGraphRelationBuilder
returns aRelationMap
instance which makes this easy: 🔥RelationMap
is provided by 📦 typeorm-relations, read its docs to see what else you can do with it.Additionally, make sure you're aware of TypeORM's own breaking changes when upgrading from v0.2.x to v0.3.0.
This discussion was created from the release v2.0.0.
Beta Was this translation helpful? Give feedback.
All reactions