profusion / sgqlc

Simple GraphQL Client
https://sgqlc.readthedocs.io/
ISC License
506 stars 85 forks source link

Add support for `UUID` Type #223

Closed neetaBirajdar closed 1 year ago

neetaBirajdar commented 1 year ago

🚀 Feature Request

Add support for UUID in sgqlc.types

Description

There are the following types supported by sgqlc:

int, str, boolean, float, id, enum, union, datetime , non_null , list_of (Maybe more)

But there is no support for UUID.

Most of the people who work with databases in the backend, need a unique identification for entities that they can use as a primary key. This can be of type str but not always.

UUID is used by many(including my organization). So, it would be great to have this UUID Type supported.

Implementation details

For example: I want to create a user and update that with its uuid.

The class for this User will look like this:

class User(Type):
    uuid=UUID
    code=str
    name=str
    createdAt=datetime
  1. Create with uuid type in response:
mutation MutationCreateUser($code: String!, $name: String!) {
  createUser(code: $code, name: $name) {
    uuid
    code
    name
    createdAt
  }
}

Variables: {"code":"user_code", "name":"user_name"}

  1. Update with created uuid in request:
mutation MutationUpdateUser($uuid: UUID! $code: String!, $name: String!) {
  updateUser(uuid: $uuid, code: $code, name: $name) {
    uuid
    code
    name
    createdAt
  }
}

Variables: {"uuid": "94fda4fb-d574-470b-82e2-0f4ec2a2db90", "code":"user_code_updated", "name":"user_name_updated"}

Note: There is a library for the uuid type(https://docs.python.org/3/library/uuid.html) which can be referred to.

Acceptance criteria

barbieri commented 1 year ago

Usually in every project that I worked with we use ID (native type, opaque, but usually encoded as string).

However, we already expose some helpers, if you could provide a patch to https://github.com/profusion/sgqlc/tree/master/sgqlc/types/uuid.py (new file), see example at https://github.com/profusion/sgqlc/blob/master/sgqlc/types/datetime.py

It should be simple, remember to add docs and doctests to cover it.

Unfortunately I'm out of time to implement it myself, but will be glad to review and integrate it (shall the linters and tests pass, please run utils/git/install-git-hooks.sh so you get the pre-commit hooks, or manually run utils/git/pre-push

neetaBirajdar commented 1 year ago

Thank you so much for replying @barbieri. I will take care of adding this :) and raise Pull Request for this.

barbieri commented 1 year ago

closed by #224