Relay: wrong mock for array of string

Created on 26 Jul 2019  路  2Comments  路  Source: facebook/relay

Most helpful comment

Thanks for reporting this, @sibelius!

I specifically include this field in this example to illustrate the limitations of the MockPayloadGenerator for scalar fields.

Since we don't have any type information about scalar fields in the Normalization ASTs (https://github.com/facebook/relay/blob/8f10f55275c59740a703f0ff7b09fa0f43d143f9/packages/relay-compiler/codegen/__tests__/__snapshots__/compileRelayArtifacts-test.js.snap#L6276), whether the filed is plural, nullable, Integer or Float, etc - we don't know this. And for those cases, we're defaulting to String.

This can be solved by using @relay_test_operation: https://relay.dev/docs/en/testing-relay-components#relay_test_operation

Or providing a custom mock resolver for the String type or for concrete object type of the parent.

All 2 comments

cc @alunyov

Thanks for reporting this, @sibelius!

I specifically include this field in this example to illustrate the limitations of the MockPayloadGenerator for scalar fields.

Since we don't have any type information about scalar fields in the Normalization ASTs (https://github.com/facebook/relay/blob/8f10f55275c59740a703f0ff7b09fa0f43d143f9/packages/relay-compiler/codegen/__tests__/__snapshots__/compileRelayArtifacts-test.js.snap#L6276), whether the filed is plural, nullable, Integer or Float, etc - we don't know this. And for those cases, we're defaulting to String.

This can be solved by using @relay_test_operation: https://relay.dev/docs/en/testing-relay-components#relay_test_operation

Or providing a custom mock resolver for the String type or for concrete object type of the parent.

Was this page helpful?
0 / 5 - 0 ratings