Fork me on GitHub
#graphql
<
2019-01-15
>
Ian Fernandez17:01:34

I'm using lacinia and defining a type, there is a way to define an "OR" type

Ian Fernandez17:01:45

{:object {:a {:fields {:b {:type (or nil Int)}}}}

souenzzo17:01:46

:type (non-null Int)

Ian Fernandez17:01:24

because GraphQL is returning me like:

errors": [
    {
      "message": "Invalid value for a scalar type.",
      "locations": [
        {
          "line": 4,
          "column": 3
        }
      ],
      "path": [
        "b"
      ],
      "extensions": {
        "type": "Int",
        "value": "\"\""
      }

Ian Fernandez17:01:33

but I want to type "b" be nullable

Ian Fernandez17:01:00

sometimes b does not have a value

Ian Fernandez17:01:24

I will mock to a String then... =\

souenzzo17:01:45

clj -Srepro -Sdeps '{:deps {com.walmartlabs/lacinia {:mvn/version "0.31.0"}}}' -e "(require '[com.walmartlabs.lacinia.schema :as schema]) (schema/compile '{:object {:a {:fields {:b {:type Int}}}}})" works in my machine

souenzzo17:01:06

clj -Srepro -Sdeps '{:deps {com.walmartlabs/lacinia {:mvn/version "0.31.0"}}}' -e "(require '[com.walmartlabs.lacinia.schema :as schema]) (schema/compile '{:object {:a {:fields {:b {:type (non-null Int)}}}}})" too

Ian Fernandez18:01:07

it worked here both, but the problem was in the query

3Jane17:01:42

types are nullable by default in graphql (I don’t know about Lacinia specifically)

3Jane17:01:59

were you trying to return an empty string?

Ian Fernandez18:01:18

yeah, empty string or number

Ian Fernandez18:01:29

I used String type

timgilbert20:01:18

I don't think gql lets you have a type that is either a number or string

lilactown20:01:40

it kinda does but it's gross

timgilbert20:01:47

Or, you'd have to explicitly create a union type and then declare that in your schema

☝️ 10
hlship23:01:35

Union types are for objects only; to accomplish a "string or a number" you need to define a new scalar. We actually have one due to a mistake slipping out into production, it's not a big deal.

👍 5
hlship23:01:47

But I think the issue here is why is a numeric field getting an empty string passed up in the request?

timgilbert20:01:19

More commonly I think you'd define an object that had both a string and a number field, and leave one or the other as null.

madstap20:01:30

I don't know about gql genrally, but lacinia won't let you have scalars as members of union types. What you could do is create a custom scalar.

kwladyka21:01:42

What libraries /solutions do you use around GraphQL?

kwladyka21:01:01

graphql-clj vs lacinia?

kwladyka21:01:12

Lacinia looks better supported from github stats

kwladyka22:01:43

oh I see both of this libraries based on different inputs

kwladyka22:01:10

Is lacincia stable to use on production?

kwladyka22:01:24

Can I translate schema.edn to schema.txt ? I mean from edn format to standard GraphQL format

lilactown22:01:13

many people are using lacinia in production

kwladyka22:01:22

oh it was answer for first question 🙂

lilactown22:01:50

you can also use introspection to generate the GraphQL SDL

👍 5
kwladyka22:01:53

Do you use login only in GraphQL or by REST and later allow users to use GraphQL?

lilactown22:01:11

we have an authentication/authorization layer that is separate from GraphQL

kwladyka22:01:45

I am trying to decide about that now 🙂

lilactown22:01:25

we have other services that aren't GraphQL

lilactown22:01:59

we have a service specifically for authentication, another for authorization

lilactown22:01:03

it made more sense for our system