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

Question: How to convert JSONString to JSON when using SGQLC #148

Closed
gu3sss opened this issue May 24, 2021 · 10 comments
Closed

Question: How to convert JSONString to JSON when using SGQLC #148

gu3sss opened this issue May 24, 2021 · 10 comments
Assignees

Comments

@gu3sss
Copy link

gu3sss commented May 24, 2021

Couple of columns in my mysql backend table are of type JSON. When trying to use SGQLC codegen to generate the schema, I see that Sgqlc marked these field with type 'JSONString'. This JSONString displays as String in response obviously and I am expecting the response to be in JSON format. Is this acheivable?

Please refer to the status_types_for_notification and email_ids fields below.

Expected result:

  "message": {
    "data": {
      "all_status": {
        "pageInfo": {
          "startCursor": "YXJyYXljb25uZWN0aW9uOjA=",
          "endCursor": "YXJyYXljb25uZWN0aW9uOjE=",
          "hasNextPage": false
        },
        "total_count": 2,
        "edges": [
          {
            "cursor": "YXJyYXljb25uZWN0aW9uOjA=",
            "node": {
              "id": "Q29tcG9uZW50U3RhdHVzTm9kZTooJ2M5YjM5MTc3LWExYjUtNDgwYy04NGRhLTZmOWNiZDNhM2QyZScsICdPSScsIDAp",
              "pipeline_id": "c9b39177-a1b5-480c-84da-6f9cbd3a3d2e",
              "status_types_for_notification": [
                "SUCCEEDED",
                "FAILED"
              ],
              "email_ids": [
                "email1",
                "email2"
              ]
            }
          }
        ]
      }
    }
  }
}

Actual Result:

    "message": {
        "data": {
            "all_status": {
                "pageInfo": {
                    "startCursor": "YXJyYXljb25uZWN0aW9uOjA=",
                    "endCursor": "YXJyYXljb25uZWN0aW9uOjE=",
                    "hasNextPage": false
                },
                "total_count": 2,
                "edges": [
                    {
                        "cursor": "YXJyYXljb25uZWN0aW9uOjA=",
                        "node": {
                            "id": "Q29tcG9uZW50U3RhdHVzTm9kZTooJ2M5YjM5MTc3LWExYjUtNDgwYy04NGRhLTZmOWNiZDNhM2QyZScsICdPSScsIDAp",
                            "pipeline_id": "c9b39177-a1b5-480c-84da-6f9cbd3a3d2e",
                            "status_types_for_notification": "[\"SUCCEEDED\", \"FAILED\"]",
                            "email_ids": "[\"email1\", \"email2\"]"
                        }
                    }
                ]
            }
        }
    }
}
@barbieri
Copy link
Member

yes, you need to declare them as scalars, refer to the built-in such as https://github.com/profusion/sgqlc/blob/master/sgqlc/types/datetime.py

do you write this schema manually? If so, just declare a type like that and refer to it. If you don't, if you use schemagen, I'm afraid I don't have any code that will import some extra file and use it (like it does for Relay/Node and DateTime), but it's easy to add and I can do it for you

@barbieri barbieri self-assigned this Jun 2, 2021
@barbieri
Copy link
Member

barbieri commented Jun 2, 2021

@gu3sss ping? do you have more details?

@gu3sss
Copy link
Author

gu3sss commented Jun 2, 2021

Am sorry for the delay! I am not using schemagen. I created my own schema mentioned here.

@gu3sss
Copy link
Author

gu3sss commented Jun 2, 2021

Are you suggesting me to build a new scalar of type Json just for my code or to contribute back to SGQLC community?

@barbieri
Copy link
Member

barbieri commented Jun 2, 2021

that can be the case as well, but if you don't want to contribute back you can simply use it in your schema, you declare a class (like those in sgqlc/types/datetime.py) and then you use it in the schema declaration.

@gu3sss
Copy link
Author

gu3sss commented Jun 2, 2021

understood! I will give it a shot. thanks!

@barbieri
Copy link
Member

@gu3sss any updates on this?

@gu3sss
Copy link
Author

gu3sss commented Jun 22, 2022

@barbieri Please close this. I implemented a work around for this.

@gu3sss gu3sss closed this as completed Jun 22, 2022
@barbieri
Copy link
Member

@gu3sss would you mind saying how you did it? Asking because of #206 may use it.

@gu3sss
Copy link
Author

gu3sss commented Jun 22, 2022

I post processed the output I got using graphql.

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

No branches or pull requests

2 participants