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

GraphQL API doesn't support inserting null values for some types #1347

Closed
marksurnin opened this issue Oct 18, 2021 · 2 comments · Fixed by #1380
Closed

GraphQL API doesn't support inserting null values for some types #1347

marksurnin opened this issue Oct 18, 2021 · 2 comments · Fixed by #1380
Assignees
Labels
bug Something isn't working GraphQL

Comments

@marksurnin
Copy link
Contributor

We noticed that GraphQL API throws an exception when we try to insert null for some data types: list, map, tuple and udt.

For example, if there's a table such as

CREATE TABLE type_test.test (
    a int PRIMARY KEY,
    b list<int>,
    c map<int, text>,
    d frozen<tuple<int, int>>,
    e custom_udt
)

the schema for testInput is the following, note that the types are nullable:

input testInput {
  a: Int
  b: [Int]
  c: [EntryIntKeyStringValueInput]
  d: TupleIntIntInput
  e: custom_udtUdtInput
}

When we pass null as the value for the list type:

mutation {
  inserttest(value:{a: 4, b: null}) {
    applied
  }
}

we get the following exception:

WARN  [2021-10-18 14:31:33,337] notprivacysafe.graphql.execution.SimpleDataFetcherExceptionHandler: Exception while fetching data (/inserttest) : null
java.lang.NullPointerException: null
! at io.stargate.graphql.schema.cqlfirst.dml.fetchers.DataTypeMapping.convertCollection(DataTypeMapping.java:70)
! at io.stargate.graphql.schema.cqlfirst.dml.fetchers.DataTypeMapping.toDBValue(DataTypeMapping.java:45)
! at io.stargate.graphql.schema.cqlfirst.dml.fetchers.DmlFetcher.toDBValue(DmlFetcher.java:224)

This happens when inserting null for columns c, d, and e as well.

Would the fix be to make methods such as convertCollection, convertMap, etc. in DataTypeMapping return null when graphQLValue is null or is there more to this?


For context, we're migrating some use cases to Stargate that insert null values to remove existing values, which is why we'd like to maintain parity with CQL.

cqlsh> insert into type_test.test(a, b, c, d, e) VALUES (2, null, null, null, null);
cqlsh> select * from type_test.test ;
 a | b    | c        | d      | e
---+------+----------+--------+------------------
 1 |  [2] | {3: '3'} | (4, 4) | {one: 1, two: 2}
 2 | null |     null |   null |             null

We're aware that we could insert null if we omit this field from a mutation but this doesn't work for upserts where we'd like to overwrite existing values with null. Thanks!

@dougwettlaufer dougwettlaufer added bug Something isn't working GraphQL labels Oct 18, 2021
@dougwettlaufer
Copy link
Contributor

@olim7t what are your thoughts here?

@olim7t
Copy link
Collaborator

olim7t commented Oct 28, 2021

Yes we need to fix that.
For lists I think passing an empty list would achieve the same effect since CQL considers empty list and null the same, but it will be more user-friendly to accept null as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working GraphQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants