microsoft / cppgraphqlgen

C++ GraphQL schema service generator
MIT License
325 stars 45 forks source link

Suggestion: Clearer schemagen error messages #300

Open ckaminski opened 5 months ago

ckaminski commented 5 months ago

Using the schema:

type ContactMethod { 
    id:     ID
    name:   String
    method_type: ContactMethodType
    method: ContactMethodValue
}
type Query { 
    getContactById(id: ID) : Contact
    getContactsByName(search: String) : [Contact]
    #getContactsByContactMethod(search: String) : [Contact]
    getContactsByContactMethod(search: ContactMethod) : [Contact]
}

I get the error message below when building:

Generating graphqllib GraphQL schema Invalid argument type: ContactMethod line: 69 column: 32 CMake Error at C:/repos/cpp/appserver/x64-windows/vcpkg_installed/x64-windows/share/cppgraphqlgen/cppgraphqlgen-update-schema-files.cmake:40 (message): Schema generation failed!

I modify this as follows and it works - perhaps it could point out it should be an input type if not a built-in?

type ContactMethod { 
    id:     ID
    name:   String
    method_type: ContactMethodType
    method: ContactMethodValue
}
input ContactMethodQueryInput { 
    name:   String
    method_type: ContactMethodType
}
type Query { 
    getContactById(id: ID) : Contact
    getContactsByName(search: String) : [Contact]
    #getContactsByContactMethod(search: String) : [Contact]
    getContactsByContactMethod(search: ContactMethodQueryInput) : [Contact]
}

Yeah, I'm pretty rusty at GraphQL - this took longer for me to find that I was happy with. :)