这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ For example, see [here](https://hasura.io/docs/1.0/graphql/manual/api-reference/
- server: support special characters in JSON path query argument with bracket `[]` notation, e.g `obj['Hello World!']` (#3890) (#4482)
- server: add graphql-engine support for timestamps without timezones (fix #1217)
- server: support inserting unquoted bigint, and throw an error if value overflows the bounds of the integer type (fix #576) (fix #4368)
- console: while deriving action, map selection set of parent mutation to action's returning type (#4530)
- console: change react ace editor theme to eclipse (close #4437)
- console: fix columns reordering for relationship tables in data browser (#4483)
- console: format row count in data browser for readablity (#4433)
Expand Down
14 changes: 13 additions & 1 deletion console/src/shared/utils/deriveAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ const deriveAction = (
const operationDefinition = rootFields[0];
const operationName = operationDefinition.name.value;

const selectedFields = operationDefinition.selectionSet.selections.map(s => {
return s.name.value;
});

// get action name if not provided
if (!actionName) {
actionName = operationAst.definitions[0].name
Expand Down Expand Up @@ -212,7 +216,10 @@ const deriveAction = (
Object.values(getTypeFields(refOperationOutputType)).forEach(
outputTypeField => {
const fieldTypeMetadata = getUnderlyingType(outputTypeField.type);
if (isScalarType(fieldTypeMetadata.type)) {
if (
isScalarType(fieldTypeMetadata.type) &&
selectedFields.includes(outputTypeField.name)
) {
outputTypeFields[outputTypeField.name] = wrapTypename(
fieldTypeMetadata.type.name,
fieldTypeMetadata.wraps
Expand All @@ -221,6 +228,11 @@ const deriveAction = (
}
);
});
if (!Object.keys(outputTypeFields).length) {
throw new Error(
`no scalar found in the selection set of your operation; only scalar fields of the operation get mapped onto the output type of the derived action`
);
}

Object.keys(outputTypeFields).forEach(fieldName => {
actionOutputType.fields.push({
Expand Down