[payload-generator] Work with nonnullable lists
This commit is contained in:
Родитель
4c7dc4c5a7
Коммит
f62a1a39f3
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
executeSync,
|
||||
getNamedType,
|
||||
getNullableType,
|
||||
getOperationAST,
|
||||
isAbstractType,
|
||||
isCompositeType,
|
||||
|
@ -103,6 +104,7 @@ export function generate(
|
|||
}
|
||||
|
||||
const namedReturnType = getNamedType(info.returnType);
|
||||
const isList = isListType(getNullableType(info.returnType));
|
||||
if (isCompositeType(namedReturnType)) {
|
||||
// TODO: This 'is list' logic is also done by the value resolver,
|
||||
// so probably need to refactor this code to actually leverage that.
|
||||
|
@ -126,7 +128,7 @@ export function generate(
|
|||
};
|
||||
return result;
|
||||
};
|
||||
if (isListType(info.returnType)) {
|
||||
if (isList) {
|
||||
const value = source[selectionName];
|
||||
const result = Array.isArray(value)
|
||||
? value.map(generateValue)
|
||||
|
@ -146,7 +148,7 @@ export function generate(
|
|||
info,
|
||||
source.__abstractType || info.parentType,
|
||||
resolveValue,
|
||||
isListType(info.returnType),
|
||||
isList,
|
||||
);
|
||||
return result;
|
||||
} else if (isEnumType(namedReturnType)) {
|
||||
|
@ -157,7 +159,7 @@ export function generate(
|
|||
: String(value).toUpperCase();
|
||||
}
|
||||
const enumValues = namedReturnType.getValues().map((e) => e.name);
|
||||
return isListType(info.returnType) ? enumValues : enumValues[0];
|
||||
return isList ? enumValues : enumValues[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,16 @@
|
|||
diff --git a/node_modules/relay-test-utils-internal/lib/testschema.graphql b/node_modules/relay-test-utils-internal/lib/testschema.graphql
|
||||
index ce0e0f3..1071e39 100644
|
||||
index ce0e0f3..5e96d03 100644
|
||||
--- a/node_modules/relay-test-utils-internal/lib/testschema.graphql
|
||||
+++ b/node_modules/relay-test-utils-internal/lib/testschema.graphql
|
||||
@@ -485,7 +485,7 @@ interface FeedUnit {
|
||||
|
||||
type FriendsConnection {
|
||||
count: Int
|
||||
- edges: [FriendsEdge]
|
||||
+ edges: [FriendsEdge]!
|
||||
pageInfo: PageInfo
|
||||
}
|
||||
|
||||
@@ -1008,6 +1008,7 @@ type User implements Named & Node & Actor & HasJsField & Entity & AllConcreteTyp
|
||||
last: Int
|
||||
orderby: String
|
||||
|
|
Загрузка…
Ссылка в новой задаче