overblog / GraphQLBundle

This bundle provides tools to build a complete GraphQL API server in your Symfony App.
MIT License
788 stars 222 forks source link

Could not find type with alias "Subscription". Did you forget to define it? #1139

Open jsakars opened 1 year ago

jsakars commented 1 year ago
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Version/Branch 1.0.0

Using latest stable Symfony and this bundle and given the following config/packages/graphql.yaml content:

overblog_graphql:
    definitions:
        schema:
            query: Query
            mutation: Mutation

Symfony profiler shows the following error when trying to access GraphQL section: An exception has been thrown during the rendering of a template ("Could not find type with alias "Subscription". Did you forget to define it?")..

Now with the following config/packages/graphql.yaml content:

overblog_graphql:
    definitions:
        schema:
            query: Query

Symfony profiler shows the following error when trying to access GraphQL section: An exception has been thrown during the rendering of a template ("Could not find type with alias "Mutation". Did you forget to define it?").

It seems that GraphQL profiler expects ALL types (query, mutations, subscription) to be defined even though one might not have some of them (e.g. only the queries).

It seems to work adding some dummy type definition e.g.:

type Subscription {
    id: ID!
}

Is there something missing in the default configuration?

Vincz commented 1 year ago

Hi @jsakars. I have not been able to reproduce (I though I did, but I had a Subscription defined in my config). Can you confirm that you are on the last version of this bundle? Also, do you mind to send me a trace? This bug was supposed to be addressed by https://github.com/overblog/GraphQLBundle/pull/1122/files#diff-d413d9e605026f2780d7e9daf63a24695e2ec842f163b6101e3a09d8c286806e

jsakars commented 1 year ago

@Vincz hi!

thanks for looking into this. I can confirm I am on a latest stable version of this bundle - ^1.0

here is the full config/packages/graphql.yaml content:

overblog_graphql:
    definitions:
        schema:
            query: Query
            mutation: Mutation
        mappings:
            types:
                -
                    type: graphql
                    dir: "%kernel.project_dir%/config/graphql/types"
                    suffix: null
                -   type: attribute
                    dir: "%kernel.project_dir%/src"
                    suffix: null

when@dev:
    overblog_graphql:
        definitions:
            show_debug_info: true

Here is the stack trace: image

Vincz commented 1 year ago

Also related, the errors messages are not explicit anymore as webonyx perform PHP type checking on the return of type resolution.

In Schema.php line 362:                                                                                                               
GraphQL\Type\Schema::resolveType(): Return value must be of type GraphQL\Type\Definition\Type, null returned  

So we don't know what type is missing in case of missing type.

vitek-rostislav commented 11 months ago

Hi, any news on this, please?

Vincz commented 10 months ago

@vitek-rostislav Do you still have the issue using the latest commits ? (using master) ?

vitek-rostislav commented 10 months ago

Hi, @Vincz, I tried it now using master and sadly yes, the problem is still there. We are using a similar configuration - just queries and mutations, the config is here - https://github.com/shopsys/shopsys/blob/14.0/project-base/app/config/packages/overblog_graphql.yaml

Vincz commented 10 months ago

Ok, I'll check asap and publish a new version.

kasperh90 commented 8 months ago

stack.txt I just got this issue right now as well. I am using v1.10

See attached file for the stack trace provided by Symfonys exception page.

edhgoose commented 8 months ago

We've just updated to 1.10 and are hitting the same problem too.

We've written our own wrapper to handle some customised generation we do, so we're calling:

        $schema = $this->executor->getSchema();
        SchemaPrinter::doPrint($schema)

We've found the fix proposed to add $typeResolver->setIgnoreUnresolvableException(true); works, but it'd be great to try and determine why this happens.

Our config is like this:

overblog_graphql:
    definitions:
        config_validation: "%kernel.debug%"
        auto_compile: true
        schema:
            query: Query
            mutation: Mutation
            types:
                ... types

Happy to help debug it if we can.

Vincz commented 8 months ago

It's fixed on master. I'll check the other pending PR and publish a new version soon.