How to skip mocking undefined fields/optional properties #4288
Unanswered
carrie-reid-knox
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello! If this was answered somewhere else already, please point me in the right direction. I was looking at Issue 930 and Issue 1068, but couldn't find exactly what I was looking for.
I am looking for a way to have
addMocksToSchema
not mock optional properties that are not supplied.Here is my test provider that I have created:
In the above example,
Mocks
is:In the above example,
props.graphqlMocks
is:The Typescript type for
User
(which is the object we are mocking above) is:The
User
type has an optional propertymember
which can either be aMember
object or undefined. If I do not explicitly passmember: null
in my mocks, then aMember
object will be mocked. How can I ensure that any optional property that is not supplied remainsundefined
instead of being provided with a mocked value? Thank you!Beta Was this translation helpful? Give feedback.
All reactions