Giter Site home page Giter Site logo

graphql-to-elm's People

Contributors

arian avatar harmboschloo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

graphql-to-elm's Issues

How should we approach recursive input?

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

const mapInputField = (
field: GraphQLInputField,
schema: GraphQLSchema
): QueryInputField => {
const namedType: GraphQLNamedType = getNamedType(field.type);
const nullableType = getNullableType(field.type);
const typeName = namedType.name;
let value: QueryInput | undefined = undefined;
if (namedType instanceof GraphQLInputObjectType) {
const fields: GraphQLInputFieldMap = namedType.getFields();
value = {
kind: "object",
typeName,
fields: Object.keys(fields).map(key => mapInputField(fields[key], schema))

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

Optional.Absent is sending in `null`

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.

Is it a good idea to export the encode and decoder of the generated types?

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 ?

Multiple fragments generate mutually exclusive records

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
    }

Is it a good idea to have fragments defined in a separate file, like schema?

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)

`__typename` hardcoded in decoder for union types

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 }
 } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.