Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

feat(schema): Use Neo4j DateTime type for created and modfied fields #154

Merged
merged 3 commits into from
Mar 11, 2021

Conversation

alastair
Copy link
Member

@alastair alastair commented Mar 10, 2021

This was originally set to String, but it's nice to have it as a datatype that allows us to do more detailed filtering.

This isn't affected by #91 because we will always have a full datetime for created and modified.

An addition to this is to integrate #112 at a later stage.

One issue that I saw, I can perform this mutation (adding created.formatted):

mutation {
  CreateRating(
creator: "https://testuser.trompa-solid.upf.edu/profile/card#me"
        ratingValue: 8
        bestRating: 10
        worstRating: 1
        created: {formatted: "2021-03-10T15:24:38.369017+00:00"}
) {
identifier
}
}

but this one fails:

mutation {
  UpdateRating (
    identifier: "05d9272c-3d00-48dc-ab25-bdab147291ea"
    created: {formatted:"2021-03-10T15:24:38.369017+00:00"}
  ) {
    identifier
  }
}

with this message:

{
  "errors": [
    {
      "message": "No such field: formatted",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "UpdateRating"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "errors": [
            {
              "message": "No such field: formatted",
              "locations": [],
              "path": [
                "UpdateRating"
              ]
            }
          ],
          "stacktrace": [
            "Error: No such field: formatted",
            "    at new CombinedError (/app/node_modules/graphql-tools/src/stitching/errors.ts:90:5)",
            "    at Object.checkResultAndHandleErrors (/app/node_modules/graphql-tools/src/stitching/errors.ts:111:11)",
            "    at CheckResultAndHandleErrors.transformResult (/app/node_modules/graphql-tools/src/transforms/CheckResultAndHandleErrors.ts:15:12)",
            "    at /app/node_modules/graphql-tools/src/transforms/transforms.ts:37:45",
            "    at Array.reduce (<anonymous>)",
            "    at applyResultTransforms (/app/node_modules/graphql-tools/src/transforms/transforms.ts:35:21)",
            "    at /app/node_modules/graphql-tools/src/stitching/delegateToSchema.ts:104:12",
            "    at step (/app/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:32:23)",
            "    at Object.next (/app/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:13:53)",
            "    at fulfilled (/app/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:4:58)"
          ]
        }
      }
    }
  ],
  "data": {
    "UpdateRating": null
  }
}

@ChristiaanScheermeijer thinks it's related to neo4j-graphql/neo4j-graphql-js#547

@ChristiaanScheermeijer
Copy link
Collaborator

Looks good. If we set the created and updated properties automatically, nobody would need to update or set these properties manually. We might even remove them from the update/create mutations.

@alastair
Copy link
Member Author

Yes, I like the idea of removing them from the mutations.

fieldNode.arguments.push(buildArgument({ name: buildName({ name: 'created' }), value }))
}

if (action === 'Create' || action === 'Update' || action === 'Update') {
Copy link
Member Author

Choose a reason for hiding this comment

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

why action == Update twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, just saw the other commit that changed it to Merge

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, that was wrong. Fixed it right after.

Copy link
Member Author

@alastair alastair left a comment

Choose a reason for hiding this comment

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

I can't approve my own PR! but it looks good by me

@ChristiaanScheermeijer ChristiaanScheermeijer merged commit 11eda7e into staging Mar 11, 2021
@ChristiaanScheermeijer ChristiaanScheermeijer deleted the created-modified-datetime branch March 11, 2021 12:58
}

if (action === 'Create') {
fieldNode.arguments.push(buildArgument({ name: buildName({ name: 'created' }), value }))
Copy link
Member Author

Choose a reason for hiding this comment

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

I just had a thought here: What if the type has no 'created' or 'modified' fields? Here you will try and add them anyway.
All of the existing models implement ThingInterface and so have these fields, but some of the types that I defined for supporting the Annotations schema don't include them. I can add them in, but I think it makes sense that this transformer also supports the case where they're not present

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, that's a very good point. I'd assumed every type would contain these properties...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants