mirror of
https://github.com/directus/directus.git
synced 2026-01-24 04:58:08 -05:00
Graphql: Fix geometry type in arguments (#15050)
* Handle matrixes as args This was the less intrusive way I figure out. We may need to refactor this parseArgs properly in order to handle this types * App/Graphql: Send filter query as proper JSON instead of escaped string * Make panel variables readonly when no-editing Prevents Geometry type mismatch error * Fix proper way to parse args
This commit is contained in:
@@ -3,7 +3,6 @@ import { Accountability, Action, Aggregate, Filter, Query, SchemaOverview } from
|
||||
import argon2 from 'argon2';
|
||||
import {
|
||||
ArgumentNode,
|
||||
BooleanValueNode,
|
||||
execute,
|
||||
ExecutionResult,
|
||||
FieldNode,
|
||||
@@ -26,14 +25,11 @@ import {
|
||||
GraphQLString,
|
||||
GraphQLUnionType,
|
||||
InlineFragmentNode,
|
||||
IntValueNode,
|
||||
NoSchemaIntrospectionCustomRule,
|
||||
ObjectFieldNode,
|
||||
ObjectValueNode,
|
||||
SelectionNode,
|
||||
specifiedRules,
|
||||
StringValueNode,
|
||||
validate,
|
||||
ValueNode,
|
||||
} from 'graphql';
|
||||
import {
|
||||
GraphQLJSON,
|
||||
@@ -1459,43 +1455,33 @@ export class GraphQLService {
|
||||
* In order to do that, we'll parse over all ArgumentNodes and ObjectFieldNodes to manually recreate an object structure
|
||||
* of arguments
|
||||
*/
|
||||
parseArgs(
|
||||
args: readonly ArgumentNode[] | readonly ObjectFieldNode[],
|
||||
variableValues: GraphQLResolveInfo['variableValues']
|
||||
): Record<string, any> {
|
||||
parseArgs(args: readonly ArgumentNode[], variableValues: GraphQLResolveInfo['variableValues']): Record<string, any> {
|
||||
if (!args || args.length === 0) return {};
|
||||
|
||||
const parseObjectValue = (arg: ObjectValueNode) => {
|
||||
return this.parseArgs(arg.fields, variableValues);
|
||||
const parse = (node: ValueNode): any => {
|
||||
switch (node.kind) {
|
||||
case 'Variable':
|
||||
return variableValues[node.name.value];
|
||||
case 'ListValue':
|
||||
return node.values.map(parse);
|
||||
case 'ObjectValue':
|
||||
return Object.fromEntries(node.fields.map((node) => [node.name.value, parse(node.value)]));
|
||||
case 'NullValue':
|
||||
return null;
|
||||
case 'StringValue':
|
||||
return String(node.value);
|
||||
case 'IntValue':
|
||||
case 'FloatValue':
|
||||
return Number(node.value);
|
||||
case 'BooleanValue':
|
||||
return Boolean(node.value);
|
||||
case 'EnumValue':
|
||||
default:
|
||||
return node.value;
|
||||
}
|
||||
};
|
||||
|
||||
const argsObject: any = {};
|
||||
|
||||
for (const argument of args) {
|
||||
if (argument.value.kind === 'ObjectValue') {
|
||||
argsObject[argument.name.value] = parseObjectValue(argument.value);
|
||||
} else if (argument.value.kind === 'Variable') {
|
||||
argsObject[argument.name.value] = variableValues[argument.value.name.value];
|
||||
} else if (argument.value.kind === 'ListValue') {
|
||||
const values: any = [];
|
||||
|
||||
for (const valueNode of argument.value.values) {
|
||||
if (valueNode.kind === 'ObjectValue') {
|
||||
values.push(this.parseArgs(valueNode.fields, variableValues));
|
||||
} else {
|
||||
if (valueNode.kind === 'Variable') {
|
||||
values.push(variableValues[valueNode.name.value]);
|
||||
} else {
|
||||
values.push((valueNode as any).value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
argsObject[argument.name.value] = values;
|
||||
} else {
|
||||
argsObject[argument.name.value] = (argument.value as IntValueNode | StringValueNode | BooleanValueNode).value;
|
||||
}
|
||||
}
|
||||
const argsObject = Object.fromEntries(args.map((arg) => [arg.name.value, parse(arg.value)]));
|
||||
|
||||
return argsObject;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<component
|
||||
:is="`interface-${inter}`"
|
||||
v-bind="options"
|
||||
:disabled="true"
|
||||
:value="value"
|
||||
:width="fieldWidth"
|
||||
:type="type"
|
||||
|
||||
@@ -59,5 +59,14 @@ export function formatQuery({ collection, query }: QueryInfo): Record<string, an
|
||||
// TBD @TODO
|
||||
}
|
||||
|
||||
if (query.filter) {
|
||||
try {
|
||||
const json = String(query.filter);
|
||||
formattedQuery.__args.filter = JSON.parse(json);
|
||||
} catch {
|
||||
// Keep current value there
|
||||
}
|
||||
}
|
||||
|
||||
return formattedQuery;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user