Skip to content

fix(graphql): escape every $ in names, including enum values, relationships and maps - #303

Merged
jamieshorten merged 2 commits into
accordproject:mainfrom
aaryanpawar16:aaryanpawar16/i302/graphql-dollar-names
Nov 13, 2026
Merged

jamieshorten merged 2 commits into
accordproject:mainfrom
aaryanpawar16:aaryanpawar16/i302/graphql-dollar-names

Conversation

@aaryanpawar16

Copy link
Copy Markdown
Contributor

Closes #302

toGraphQLName() only replaced the first $, and enum values, relationship names and map names were written without it, so models using $ in those names produced SDL that graphql-js rejects (for example Expected Name, found "$").

Changes

  • Replace every $ in toGraphQLName() (/\$/g instead of the first match only)
  • Use toGraphQLName() for enum values, relationship names, map names, and the key and value types of maps that are not primitive. Fields that refer to a map already used it, so the names did not match.
  • Add a test that builds the SDL for a model with $ in each kind of name and checks it with graphql-js buildSchema. It fails on main and passes with this change.

Flags

  • Not included: non-ASCII names (e.g. Café, 名前) and enum values named true, false or null, which graphql-js also rejects. They need a decision on how names should be changed, so they are only mentioned in bug(graphql): $ in enum values, relationships, map names and repeated $ produces invalid GraphQL #302.
  • The # <type> comment on a relationship line keeps the original Concerto type name, so it can still contain $ (it is a GraphQL comment).
  • The new test sets ENABLE_MAP_TYPE for maps and restores it afterwards.
  • fix(graphql): generate valid GraphQL for empty enums #273 also edits the GraphQL visitor (empty enums). The changes do not overlap, but I will rebase if it merges first.
  • I used an AI assistant (Claude) while writing and testing this change; I have read and verified the changes.

Screenshots or Video

Not applicable. The reproduction and its output are in #302.

Related Issues

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary (not necessary: no documented behaviour changes)
  • Merging to main from fork:branchname

…nships and maps

GraphQL names cannot contain $, and toGraphQLName() exists to replace it,
but it was not applied consistently, so the generated SDL was rejected by
graphql-js ("Expected Name, found "$"") for models with $ in their names:

- toGraphQLName() used replace('$', '_'), which only replaces the first $
- enum values were written without toGraphQLName()
- relationship names were written without toGraphQLName()
- map names, and the key and value types of maps that are not primitive,
  were written without toGraphQLName(), so they also no longer matched
  the escaped name used by the fields that refer to them

Replace every $ and apply toGraphQLName() to those names. The test builds
the SDL for a model that uses $ in each kind of name and checks it with
graphql-js buildSchema.

Closes accordproject#302

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Aaryan Pawar <pawararyan989@gmail.com>
@mira-accord-project

Copy link
Copy Markdown

Thanks for your first contribution to Accord Project, and for opening #302 with the details alongside this PR. The CI workflows have been approved and are passing. The PR now waits for review from the Concerto maintainers. If you push more changes, the checks will run again, and it helps if the commits are signed off (DCO).

Drafted by an Accord Project agent, reviewed by a maintainer.

@mira-accord-project mira-accord-project Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this fix, and welcome to the project. The /\$/g change in toGraphQLName correctly fixes the single-replacement bug. Applying it to enum values, map names and key/value types, and relationship names closes the other places where a $ could reach the output. Keeping the original name in the relationship comment is a sensible choice. The new test is also useful: it checks the generated SDL against buildSchema from graphql, which is already a pinned devDependency. I found nothing blocking. One small gap in the test is below. Once that is covered, this looks ready for a maintainer to approve.

Nothing blocking; some suggestions below. Findings: 1 nit.


Automated review by Mira, an Accord Project agent, at 544dc30. Findings are labelled blocking, should-fix or nit; a maintainer makes the final call.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests omit non-primitive map key/value type names containing $, leaving regressions in either escaping call undetected.

1 open issue
What changed in this PR

Fixes GraphQL name escaping for Concerto models containing $, addressing issue #302 so generated declarations and references use consistent names.

Changes:

  • Replace every $ in names, rather than only the first occurrence.
  • Apply escaping to enum values, relationships, map names, and non-primitive map type references.
  • Add regression coverage that validates generated SDL with graphql-js and restores the map feature flag afterward.
File Description
test/​codegen/​fromcto/​graphql/​graphqlvisitor.js Adds dollar-name regression coverage and schema validation.
lib/​codegen/​fromcto/​graphql/​graphqlvisitor.js Applies dollar-sign escaping consistently across generated names.

Review effort: Balanced

…types

The regression test for names with $ used String as the key and the value
of its map, so the toGraphQLName() calls added to visitMapDeclaration() for
non-primitive key and value types never ran: reverting either of them did
not fail any test.

Use a declared type with $ in its name as the value of the map in the model
that is validated with graphql-js, and add a test for a scalar key. The
latter only checks the emitted lines, because scalar declarations are not
written yet (accordproject#248), so graphql-js would reject the SDL for that other reason.

Both calls were reverted in turn to check that the tests now fail.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Aaryan Pawar <pawararyan989@gmail.com>
@aaryanpawar16

Copy link
Copy Markdown
Contributor Author

I pushed a follow-up commit (bc3003d) for the test gap flagged in the automated reviews. The regression test now uses a declared type with $ in its name as the map value, so the toGraphQLName() calls for non-primitive key and value types are exercised, and I added a test for a scalar map key. I reverted each of those calls in turn and confirmed the tests fail without them.

The workflows for the new commit are waiting for approval. Could a maintainer approve them when you have a moment? Locally, the GraphQL tests pass (670 passing). npm test still exits 1 only because branch coverage is 95.91% against the 96% threshold. Upstream main shows 95.9% on the same machine, since the Docker and tool-based verification tests are skipped here.

@mira-accord-project mira-accord-project Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this fix, and for the thorough tests. The change is small and well targeted: toGraphQLName now replaces every $ rather than only the first, and enum values, relationship names, map names and non-primitive map keys and values now go through it, so the generated GraphQL stays valid for names like Le$ve$l or some$field$name. I checked each changed call site and found no other place in the visitor that writes a Concerto name unescaped. The new tests cover each case, including a buildSchema check with graphql-js and a non-primitive map key, and CI is green. I have no changes to request. The PR is ready for a maintainer's approval once the two open review threads, which the latest commit addresses, are resolved.

No problems found.


Automated review by Mira, an Accord Project agent, at bc3003d. Findings are labelled blocking, should-fix or nit; a maintainer makes the final call.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the changes to GraphQL identifier escaping.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@jamieshorten
jamieshorten merged commit feaee71 into accordproject:main Nov 13, 2026
36 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(graphql): $ in enum values, relationships, map names and repeated $ produces invalid GraphQL

3 participants