graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Unable to generate clients for schemas generated by `Prisma.io`

Open wilsonrivera opened this issue 2 years ago • 1 comments

Is your feature request related to a problem?

I've been working with a schema file generated by Prisma.io but very early on found the issue that said generated uses field equals which causes conflict with the Equals method (error message below)

error CS0102: The type 'StringFilter' already contains a definition for 'Equals'

And the type generated by Prisma.io looks like this:

input StringFilter {
  contains: String
  endsWith: String
  equals: String
  gt: String
  gte: String
  in: [String!]
  lt: String
  lte: String
  not: NestedStringFilter
  notIn: [String!]
  startsWith: String
}

After deep diving into how the generator works, I was able to isolate and mitigate the issue by modifying the method RegisterInputObjectType with this code:

...
rename = inputField.Directives.SingleOrDefault<RenameDirective>();
var fieldName = rename?.Name ?? inputField.Name;
if (string.Equals("equals", fieldName, StringComparison.OrdinalIgnoreCase))
{
    fieldName = "equal";
}

fields.Add(new InputFieldModel(
    GetClassName(fieldName),
...

This solution, although hacky, works but would rather a more robust solution. I don't know if the @rename directive would come in handy with this, but realistic solution, as the team that works with Prisma.io is constantly making changes and at this point, the schema file is over 3k line.

The solution you'd like

Like I stated before, this could be solved with some changes to the RegisterInputObjectType method. What comes to mind is maybe have a way to provide field mappings in the configuration file or optionally, a way to hook a field name mapper into the IDocumentAnalyzerContext interface (as it is passed to the aforementioned method).

I don't know if these are the best approach, but is what first came to mind.

Product

Strawberry Shake

wilsonrivera avatar Aug 04 '22 01:08 wilsonrivera

I think we can enhance the rename directive to allow something like @rename(to: "equal" target: "*.equals"). Not sure yet.

michaelstaib avatar Aug 06 '22 10:08 michaelstaib

This also occurs for Version in a schema like below:

type QueryRoot {
  version(id: Int!): Version
}

This will generate code with multiple Version property definitions and parameter names (i.e. The parameter name 'version' is a duplicate and The type 'XXX' already contains a definition for 'Version'). A way to rename things in the generated code, or better namespacing of generated properties (__StrawberryVersion), would be a good workaround.

anna-is-cute avatar Oct 13 '22 10:10 anna-is-cute