Skip to content
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

Omit types not used by loaded resolvers #415

Merged
merged 3 commits into from
Sep 7, 2019
Merged

Conversation

MichalLytek
Copy link
Owner

This PR fix the leakages in generated schema that were unintended. Now, the buildSchema function will produce GraphQLSchema only with operations declared in classes provided in resolvers option 🎉

This also apply to other types (object, inputs, interfaces) - they will be emitted in schema only if they are explicitly used in used types.
So if you have declared 10 object types implementing an interface but don't use them directly as a return type of an operation, part of an union type or as a field type, they will be omitted too.

In that case you might want to provide the orphaned types explicitly to buildSchema option to emit them too as they might be used indirectly, e.g. by the underlying database or something:

import { FirstResolver, SecondResolver } from "../app/src/resolvers";
import { FirstObject } from "../app/src/types";
// ...
const schema = await buildSchema({
  resolvers: [FirstResolver, SecondResolver],
  // here provide all the types that are missing in schema
  orphanedTypes: [FirstObject],
});

And because we don't have control of glob-imported files with resolvers and types, this feature doesn't apply if you use the indirect, glob path version of resolvers options property. In that case it will still emit the whole metadata storage content as earlier 😞

Closes #110 🔒

@MichalLytek MichalLytek added the Enhancement 🆕 New feature or request label Sep 6, 2019
@MichalLytek MichalLytek added this to the 1.0.0 release milestone Sep 6, 2019
@MichalLytek MichalLytek self-assigned this Sep 6, 2019
@codecov
Copy link

codecov bot commented Sep 6, 2019

Codecov Report

Merging #415 into master will decrease coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #415      +/-   ##
==========================================
- Coverage   94.79%   94.66%   -0.13%     
==========================================
  Files          71       71              
  Lines        1152     1163      +11     
  Branches      214      219       +5     
==========================================
+ Hits         1092     1101       +9     
- Misses         57       59       +2     
  Partials        3        3
Impacted Files Coverage Δ
src/utils/buildSchema.ts 100% <100%> (ø) ⬆️
src/schema/schema-generator.ts 96.68% <100%> (-0.75%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0c8cd5d...26a54af. Read the comment docs.

@MichalLytek MichalLytek merged commit edf4706 into master Sep 7, 2019
@MichalLytek MichalLytek deleted the omit-not-used-types branch September 7, 2019 14:44
@MichalLytek MichalLytek restored the omit-not-used-types branch September 7, 2019 14:44
@MichalLytek MichalLytek deleted the omit-not-used-types branch September 7, 2019 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement 🆕 New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Omit Types from schema if not used by loaded resolvers
1 participant