harmboschloo / graphql-to-elm Goto Github PK
View Code? Open in Web Editor NEWValidates graphql queries and converts them to elm code.
License: BSD 3-Clause "New" or "Revised" License
Validates graphql queries and converts them to elm code.
License: BSD 3-Clause "New" or "Revised" License
given such a schema
schema {
query: query
}
type query {
string(node: Node): String
}
input Node {
name: String
child: Node
}
this works
query {
string(node: { name: "" })
}
but this doesn't
query ($node: Node) {
string(node: $node)
}
node prebuild.js
reading schema ./schema.graphql
processing schema
processing enums
processing query ./query.graphql
Error: processing query ./query.graphql
RangeError: Maximum call stack size exceeded
at /Users/choonkeat/git/graphql-to-elm-try/node_modules/graphql-to-elm/lib/queries/queryIntel.js:30:15
at async Promise.all (index 0)
make: *** [run] Error 1
the infinite loop is
graphql-to-elm/src/gen/queries/queryIntel.ts
Lines 262 to 277 in d6a4e41
I tentatively added a cache and max depth limit of 10
fields: Object.keys(fields).map(key => {
let found = mapInputFieldCache[String(fields[key].type)]
if (found) {
return { ...found, name: fields[key].name }
}
return mapInputField(fields[key], schema, depth + 1)
})
};
} else if (depth >= maxDepth) {
value = {
kind: "scalar",
typeName: "jsonb"
fwiw, I'm using hasura and some inputs are akin to "sql where clauses" and is somehow recursive
What the subject says. I believe that, instead, it should be omitting the parameter entirely in the mutation query. This is leading to data being silently overwritten in the DB when that parameter should be ignored.
For pagination and deep linking purposes, I’ll need to persist Variables
as a url query. This means I need to encode and decode Variables
values.
I see encodeVariables
already exist though not exported. decodeVariables
does not exist yet.
What do you think of exporting encodeVariables
and decodeVariables
?
Given schema
type Query {
books: [Book]
}
type Book {
title: String
author: String
}
query
query {
books {
...foo
...bar
}
}
fragment foo on Book {
title
}
fragment bar on Book {
author
}
generates a type that is either Book
(title
) OR Book2
(author
)
type alias Query =
{ books : Maybe.Maybe (List (Maybe.Maybe Book3))
}
type Book3
= OnBook Book
| OnBook2 Book2
type alias Book =
{ title : Maybe.Maybe String
}
type alias Book2 =
{ author : Maybe.Maybe String
}
while expected is a plain record with both title
AND author
type alias Query =
{ books : Maybe.Maybe (List (Maybe.Maybe Book))
}
type alias Book =
{ title : Maybe.Maybe String
, author : Maybe.Maybe String
}
I have various queries/mutations that inevitably have the same selection set that ideally i'd like to only specify once, as a fragment
# ThingByID.gql
query ($thingID: ID!) {
thingByID(id: $thingID) {
...thingFields
}
}
# CreateThing.gql
mutation ($input: CreateThingInput!) {
createThing(input: $input) {
...thingFields
}
}
# UpdateThingByID.gql
mutation ($id: ID!, $input: UpdateThingInput!) {
updateThingByID(id: $id, input: $input) {
...thingFields
}
}
Might have missed the mechanism to do so, but it seems like I need to define the same fragment inside each of the above .gql
file. Can we have a standalone file instead, e.g.
# fragments.gql
fragment thingFields on Thing {
name
description
}
that graphqlToElm
function would auto-append the content of fragments.sql to each query's gql file, prior to doing the parsing?
graphqlToElm({
schema: "./src/schema.gql",
+ fragments: "./src/fragments.gql",
queries: ["./src/Queries/Messages.gql"],
it's a bit more complicated than just appending, i think, since unused fragment currently throws Unhandled promise rejection
(haven't dug deeper)
With a query where all input types have custom encoders defined then Json.Encode
is never imported in the generated module, resulting in a compilation error.
Say this schema:
type Query {
foo: SomeUnionType
}
union SomeUnionType = Connected | NotConnected
type Connected {
id: ID
}
type NotConnected {
id: ID
}
Then the query
{ foo { __typename } }
generates a decoder
(Json.Decode.field "__typename" (GraphQL.Helpers.Decode.constantString "Connected"))
however in this case, it could actually be either Connected
or NotConnected
!
The workaround is to use a query with all cases specified:
{ foo {
... on Connected { __ typename }
... on NotConnected { __typename }
} }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.