graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

How to define custom scalars when generating code?

Open njam opened this issue 6 years ago • 2 comments

I'm generating the client code with the CLI tool.

The generated file for a query "GetData" will look something like this, with a custom scalar "URL":

pub struct GetData;

pub mod get_data {

    #[doc = "URL string"]
    type URL = super::URL;
[...]

I'm struggling to find a way of defining those custom scalars outside of the generated file. Is there a way to do that? Or will that only be possible after https://github.com/graphql-rust/graphql-client/issues/245 ?

njam avatar Sep 28 '19 23:09 njam

Good point, I haven't thought about how to do this with the CLI - I hope I'll be able to work on #245 soon. In the meantime, the derive flow works (the custom scalars need to be in the same module as the struct under derive). If it's very urgent, we could try to implement a workaround (like changing the super to super::super when generating code with the CLI. What do you think?

tomhoule avatar Sep 29 '19 07:09 tomhoule

Thanks for the reply! For now I will apply a workaround locally in my project.

Please close this ticket if it's covered by #245

njam avatar Sep 29 '19 17:09 njam