Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grafast processFragment does not permit use of string arguments #2152

Open
litewarp opened this issue Aug 11, 2024 · 0 comments
Open

Grafast processFragment does not permit use of string arguments #2152

litewarp opened this issue Aug 11, 2024 · 0 comments

Comments

@litewarp
Copy link

litewarp commented Aug 11, 2024

Summary

The evalDirectiveArgDirect function, which is called during processFragment does not accept a StringValue as an acceptable value type and throws an error:

export function evalDirectiveArgDirect<T = unknown>(
  directive: DirectiveNode,
  argumentName: string,
  variableValuesStep: __TrackedValueStep,
  defaultValue: T,
): T | undefined {
  if (!directive.arguments) return defaultValue;
  const argument = directive.arguments.find(
    (a) => a.name.value === argumentName,
  );
  if (argument !== undefined) {
    const value = argument.value;
    switch (value.kind) {
      case "Variable": {
        return variableValuesStep.get(value.name.value).eval();
      }
      case "BooleanValue": {
        return value.value as any;
      }
      case "IntValue": {
        return parseInt(value.value, 10) as any;
      }
      case "NullValue": {
        return null as any;
      }
      // <------------------- NO STRINGS!!!!
      default: {
        throw new SafeError(
          `Unsupported @${directive.name}(${argumentName}:) argument; expected Variable, Boolean or null; but received '${value.kind}'`,
        );
      }
    }
  } else {
    return defaultValue;
  }
}

Steps to reproduce

Install the StreamDeferPlugin from graphile-build
Install graphql version 16.1.0-experimental-stream-defer.6
create dummy tables and add the @defer(label: "any string label will throw") directive to a fragment

Expected results

String values should be used.

Actual results

It errs
image

Additional context

{
    "dependencies": {
    "@dataplan/json": "0.0.1-beta.23",
    "@dataplan/pg": "0.0.1-beta.25",
    "@grafserv/persisted": "0.0.0-beta.26",
    "@graphile-contrib/pg-many-to-many": "2.0.0-beta.3",
    "@graphile-contrib/pg-omit-archived": "4.0.0-beta.2",
    "@graphile/operation-hooks": "^1.0.0",
    "@graphile/pg-aggregates": "0.2.0-beta.6",
    "@graphile/simplify-inflection": "8.0.0-beta.5",
    "graphile-build": "5.0.0-beta.24",
    "graphile-build-pg": "5.0.0-beta.28",
    "graphile-config": "0.0.1-beta.9",
    "graphile-export": "^0.0.2-beta.19",
    "graphql": "^16.1.0-experimental-stream-defer.6",
    "graphql-ws": "^5.16.0",
    "hono": "^4.5.1",
    "jsonwebtoken": "^9.0.2",
    "postgraphile": "5.0.0-beta.29",
    "postgraphile-plugin-connection-filter": "3.0.0-beta.3"
  },
  "devDependencies": {
    "@swc/core": "^1.6.6",
    "@swc/jest": "^0.2.36",
    "@types/express": "^4.17.21",
    "@types/jsonwebtoken": "^9.0.6",
    "@types/node": "^20.14.11",
    "bun-types": "^1.1.20",
    "jest": "^29.7.0",
    "tsup": "^8.1.2",
    "tsx": "^4.16.2",
    "typescript": "^5.5.3"
  },
}

Possible Solution

Permit String Arguments to be used(?)

Will investigate and submit a PR eventually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🐭 Shrew
Development

No branches or pull requests

2 participants