thecodingmachine / graphqlite

Use PHP Attributes/Annotations to declare your GraphQL API

Home Page:https://graphqlite.thecodingmachine.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

oprypkhantc opened this issue · comments

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.

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.

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?

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.