spawnia / sailor

A typesafe GraphQL client for PHP
MIT License
76 stars 18 forks source link

Add filename when validator return exception #105

Closed rccc closed 6 months ago

rccc commented 7 months ago

Hello,

Validator return this kind of message :

{"message":"Field \"molecule\" is not defined by type molecule_bool_exp.","extensions":{"category":"g
raphql"},"locations":[{"line":2,"column":67}]}

But does not give info about the filename.

Many thanks for your work.

Eric

spawnia commented 7 months ago

Please provide more context. What files are involved in producing the error you describe? What code is running when the error message you mention is produced?

rccc commented 6 months ago

Hello,

Sorry for late answer. Sometimes, after a schema introspection update, some graphql file may not be updates. One can contains a property that is no more defined by a type. In this case, the validator return an exception message.

In the example i gave, the property molecule is no longer defined in molecule_bool_exp but a graphql file query contains this property, that is why i get this error.

But this error do not tell abou the graphl filename ! It quite time consuming to retrieve the file...

I hope i am clear enough. Eric

spawnia commented 6 months ago

Oh, so I am assuming that running the code generation via vendor/bin/sailor codegen triggers the error? This is still unclear to me.

If that is the case: Sailor currently merges the contents of all files that contain GraphQL operations into a single GraphQL document to ease further transformations done on it, see https://github.com/spawnia/sailor/blob/9ed8e9fb2a54f757b6cbba6f299cd1a981789fc9/src/Codegen/Merger.php. The information about the filenames can not be easily included within a DocumentNode. I guess we would have to keep multiple DocumentNode instances and keep track of the filenames alongside them. This change would be quite tricky and I am not looking to implement it, so I am closing this issue. I am open to pull requests though.

rccc commented 6 months ago

@spawnia

Yes i am using the vendor/bin/sailor [codegen] command. You have perfectly answered, as the graphql files are merged, no way to get a particular filename.

No need to add complexity keeping trace of filenames.

Many thanks. I wish you a nice day.