thecodingmachine / graphqlite

Use PHP Attributes/Annotations to declare your GraphQL API
https://graphqlite.thecodingmachine.io
MIT License
555 stars 95 forks source link

Cannot use custom naming on an Input type that's also a regular Type #640

Closed oprypkhantc closed 9 months ago

oprypkhantc commented 9 months ago

Hey.

I have a class with a name that I don't want to expose in GraphQL, that's an input and a regular type at the same type:

#[Type(name: 'Address')]
#[Input(name: 'Address', default: true)]
class AddressDTO {}

I'd expect this to work; or, at, least, this to work:

#[Type(name: 'Address')]
#[Input(name: 'AddressInput', default: true)]
class AddressDTO {}

Instead, I'm getting this error when introspecting: "Expected GraphQL type \"Address\" to be either a MutableObjectType or a MutableInterfaceType. Got a TheCodingMachine\\GraphQLite\\Types\\InputType" or this error when actually trying to run a query with that type: RuntimeException: Cached type in registry is not the type returned by type mapper.

I'll PR a fix tomorrow.

oojacoboo commented 9 months ago

I wonder if default: true is the issue here. I guess the caching could be an issue. I think there are separate type mapper caches for input and output types though. So there shouldn't be a collision.

oprypkhantc commented 9 months ago

Nevermind, the second option does work. I swear I've tested it 20 times before, clearing the cache after each try and it was broken.

On that note, is the first option even supposed to work? Graphqlite automatically adds the "Input" suffix when generating a name from the class name, but it probably doesn't make sense to do so when name is manually specified?

oojacoboo commented 9 months ago

IIRC, you do need to specify the Input suffix, else you'll end up with a type name collision. It's redundant though and the Input suffix is implied.