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

DateTimeUtc: null string means null date too #2884

Merged
merged 3 commits into from
May 5, 2020

Conversation

Rahien
Copy link
Contributor

@Rahien Rahien commented May 4, 2020

when the string received in toDate is null, the date returned should also be null

Bug report

It seems that you cannot filter on null in graphQL when using DateTimeUtc

Describe the bug

I defined a field of type DateTimeUtc and I cannot filter this field to be null.

To Reproduce

Define a list like this:

todo.js:

module.exports = {
  fields: {
    name: {
      type: Text,
      isRequired: true,
    },
    completedAt: {
      type: DateTimeUtc
    }
}

Then start the server and go to the graphiql interface and execute the following query:

query {
    allTodos(where: {completedAt: null} ) {
      id
    }
  }

This will result in the following error:

{
  "errors": [
    {
      "message": "Cannot read property 'match' of null",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "allTodos"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "TypeError: Cannot read property 'match' of null",
            "    at toDate (/backend/node_modules/@keystonejs/fields-datetime-utc/dist/fields-datetime-utc.cjs.js:97:12)",
            "    at Object.completedAt (/backend/node_modules/@keystonejs/adapter-mongoose/lib/adapter-mongoose.js:647:49)",
            "    at simpleTokenizer (/backend/node_modules/@keystonejs/mongo-join-builder/lib/tokenizers.js:103:43)",
            "    at /backend/node_modules/@keystonejs/mongo-join-builder/lib/query-parser.js:55:27",
            "    at Array.map (<anonymous>)",
            "    at queryParser (/backend/node_modules/@keystonejs/mongo-join-builder/lib/query-parser.js:27:47)",
            "    at MongooseListAdapter._itemsQuery (/backend/node_modules/@keystonejs/adapter-mongoose/lib/adapter-mongoose.js:550:23)",
            "    at MongooseListAdapter.itemsQuery (/backend/node_modules/@keystonejs/keystone/lib/adapters/index.js:139:32)",
            "    at List._itemsQuery (/backend/node_modules/@keystonejs/keystone/lib/List/index.js:932:40)",
            "    at List.listQuery (/backend/node_modules/@keystonejs/keystone/lib/List/index.js:818:17)",
            "    at allTodos (/backend/node_modules/@keystonejs/keystone/lib/List/index.js:800:16)",
            "    at field.resolve (/backend/node_modules/graphql-extensions/dist/index.js:133:26)",
            "    at resolveFieldValueOrError (/backend/node_modules/graphql/execution/execute.js:467:18)",
            "    at resolveField (/backend/node_modules/graphql/execution/execute.js:434:16)",
            "    at executeFields (/backend/node_modules/graphql/execution/execute.js:275:18)",
            "    at executeOperation (/backend/node_modules/graphql/execution/execute.js:219:122)"
          ]
        }
      },
      "uid": "ck9sw28c7000iz8s63o0yg6fm",
      "name": "GraphQLError"
    }
  ],
  "data": {
    "allTodos": null
  }
}

Expected behaviour

To receive all Todo items where the completedAt field is null

System information

  • OS: macOs
  • Browser: chrome

when the string received in toDate is null, the date returned should also be null
@changeset-bot
Copy link

changeset-bot bot commented May 4, 2020

🦋 Changeset is good to go

Latest commit: 9154a24

We got this.

This PR includes changesets to release 1 package
Name Type
@keystonejs/fields-datetime-utc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@timleslie timleslie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@timleslie timleslie merged commit fd827f4 into keystonejs:master May 5, 2020
This was referenced May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants