Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signature of parse #57

Open
Coobaha opened this issue Sep 21, 2018 · 1 comment
Open

signature of parse #57

Coobaha opened this issue Sep 21, 2018 · 1 comment

Comments

@Coobaha
Copy link

Coobaha commented Sep 21, 2018

Hi @mhallin

I encountered problem trying to update Apollo cache with readQuery/writeQuery. I need to know shape of Js.Json.t which is passed to parse (Js.Json.t => t). Parse guarantees that JSON shape is valid in the runtime but it should be possible to have it as a static type based on gql query string?

Cache holds Js.Json.t. It's type is unknown currently and it will be incorrect to use t if @bsRecord is used.

module MyQuery: {
  type t;
  let make: unit => Js.t({ . parse: Js.Json.t => t, query: string, variables: Js.Json.t });
};

Would it be possible to have alternative version that trusts that data comes from graphql endpoint? In other words less runtime type save (which should not be the case if data comes from graphql server) but more exact and performant. So it will parse json only when needed, for instance for @bsRecord.

module MyQuery: {
  type jsT = <JSON type parsed from graphql query string>
  type t;
  let make: unit => Js.t({ . parse: jsT => t, query: string, variables: Js.Json.t });
};

Or at least some raw jsT could be introduced to use with apollo cache

@mhallin
Copy link
Owner

mhallin commented Oct 28, 2018

Interesting idea, I'm not sure how easy it would be to tack this on to the current implementation. Maybe this would be another "output mode" that you could specify as an argument to the ppx.

Another thing; it's not just @bsRecord that would require parsing, but unions/interfaces and enums too.

ylecornec pushed a commit to o1-labs/graphql_ppx that referenced this issue Jun 3, 2022
* feat(native): add unified definition
* chore: formatting
* chore: pin dune to less than 2
* chore: update esy-manifest, rename unused variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants