dingmaotu / gsql_client

A Python GSQL and RESTPP remote client for TigerGraph
MIT License
14 stars 6 forks source link

How to add a vertices? #1

Open SoarAnyway opened 4 years ago

SoarAnyway commented 4 years ago

Thanks for your work, it's quiet a nice project!

I want to add a new vertices through RESTPP.updata(self, graph, content) when I type content like: {'vertices': 'vertices','vertex_type': 'ElecItem', 'vertex_id': '1', 'attributes': {'p': 1}}

cause Error: RESTPPError: The payload format parsing error, the string type variable is only allowed for attribute value or operator.

dingmaotu commented 4 years ago

I recommend you to read the tigergraph restful api documentation for the exact format this method receives.

update actually calls POST /graph, the payload format looks like this:

{
 "vertices": {
    "User": {
      "id6": {
      }
    }
  },
  "edges": {
    "User":{
      "id1": {
        "Liked": {
          "User": {
            "id6" : {
              "weight" : {
                "value": 5.0
              }
            }
          }
        }
      },
      "id6": {
        "Liked_By": {
          "User": {
            "id1" : {
              "weight" : {
                "value": 1.0
              }
            }
          }
        }
      }
    }
  }
}
SoarAnyway commented 4 years ago

I recommend you to read the tigergraph restful api documentation for the exact format this method receives.

update actually calls POST /graph, the payload format looks like this:

{
 "vertices": {
    "User": {
      "id6": {
      }
    }
  },
  "edges": {
    "User":{
      "id1": {
        "Liked": {
          "User": {
            "id6" : {
              "weight" : {
                "value": 5.0
              }
            }
          }
        }
      },
      "id6": {
        "Liked_By": {
          "User": {
            "id1" : {
              "weight" : {
                "value": 1.0
              }
            }
          }
        }
      }
    }
  }
}

ok,thanks

SoarAnyway commented 4 years ago

I recommend you to read the tigergraph restful api documentation for the exact format this method receives.

update actually calls POST /graph, the payload format looks like this:

{
 "vertices": {
    "User": {
      "id6": {
      }
    }
  },
  "edges": {
    "User":{
      "id1": {
        "Liked": {
          "User": {
            "id6" : {
              "weight" : {
                "value": 5.0
              }
            }
          }
        }
      },
      "id6": {
        "Liked_By": {
          "User": {
            "id1" : {
              "weight" : {
                "value": 1.0
              }
            }
          }
        }
      }
    }
  }
}

I find a bug in RESTPP.py

def delete_vertices(self, graph, vertex_type, vertex_id=None, **kwargs):
    """
    kwargs:
        filter: attr1>30,attr2<=50,...
        limit: 10
        sort: attr1,-attr2
        timeout: 0 in seconds
    """
    endpoint = "/graph/{0}/vertices/{1}".format(graph, vertex_type)
    if vertex_id:
        endpoint += "/" + vertex_id
    return self._get(endpoint, kwargs)

line 247 must be return self._delete(endpoint, kwargs)

dingmaotu commented 4 years ago

Thanks for reporting this bug! I will fix this problem in next minor release.

SoarAnyway commented 4 years ago

I find a bug in RESTPP.py again def query(self, graph, query_name, **kwargs): """ run a specific query """ return self._get("/{0}/{1}".format(graph, query_name), kwargs) line 301 should be
return self._get("/query/{0}/{1}".format(graph, query_name), kwargs)