add example issues with type extensions #1
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.
Hello friends at The Guild -
Overview
The team I am working with has been using
graphql-modules
project for almost a year (starting with V1). We thank you and other committers for the efforts put in to the project. We have a concern regarding modularization and testing. In particular, when extending interfaces/types outside of a module's scope. We appreciate any insights you may have regarding our concern.Problem Space
The problem involves testing fields that extend
types
orinterfaces
using a reference tointerfaces
not defined by the module in test. In other words, when extending atype
, the module doesn't know whatinterface
atype
implements.To test extended
interfaces/types
, a tester defines a query to ensure their schema definition and resolvers are working as expected. However, becausetestkit.testModule
does not have a reference to the externally definedinterface
it is not possible to test the fields using fragmenting.To ease this understanding, I've modified the example app found in the
graphql-modules
repo to reflect our problem. See https://github.com/landau/graphql-modules/pull/1/files . I've also added comments in the demo code to further assist understanding. The key things to note are:type User
is nowinterface User
and has an implementingtype CommonUser
.Common*
is a pattern we're using for fields on implementingtype
s so clients can reduce the amount of fragmenting in queries, i.e.CommonUser
andLoggedInUser
both implementUser
, but fragmenting would only be necessary forLoggedInUser'
s extra fields.User
with afriends
field and has an additional scalarfoo
CommonUser
is also extended with these fieldsSocialNetwork
to exhibit our goal, but only 1/4 tests pass.testModule
which allows callers to also replace extensions for modules thatextend
interfaces
. Though this is not the source of the issue, it does exhibit the same problems with referencing interfaces from external modules.Possible Resolutions
We recognize that our problem could be solved in at least a few ways using
testkit.testModule
, but some resolutions have their own tradeoffs that we'd like to avoid because they do seem to be acting in accordance with modularity.testModule
typeDefs
config.interface
(the source of truth) changes, then tests should be updated accordingly.testModule
inheritTypeDefs
config.node
interface
.type CommonUser
andinterface User
.replaceExtensions: true
stripsextends
from both definitions and appendsimplements User
to theCommonUser
type since it's suffix matches theinterface
.interface
s.Thank you for taking the time to review our problem.