Generic data type

Hi,
I am working on the python, and i want property datatype to be generic, means data type based on the node like in neo4j. in neo4j we can have one node property datatype as int of the node type and we can have string as data type the different node of the same node type.

example:
node_type: Country
1st node property “zip_code”: 400001 (for India it is all int)
2nd node property “zip_code”: “W1B 4BD” (for London it is all string)

When i created 1st node its created schema which set the int for “zip_code”, and when my program creating 2nd node it’s giving an error

grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNKNOWN, strconv.ParseInt: parsing "W1B 4BD": invalid syntax)>
1 Like

You can try to do it this way:

type Address struct {
    ZipCode  string        `json:"zipcode,omitempty"`
    Add      []Address     `json:"add,omitempty"`
}

Data :

p := Address{
	 Add: []Address{{
            ZipCode: "W1B 4BD",
            }, {
            ZipCode: "400001",
        }},
	}

Schema:

op := &api.Operation{}
    op.Schema = `
		zipcode: string .

Query:

q := `query Me($id: string){
		me(func: uid($id)) {
		add{
		zipcode
		}}
	}`

Result:

{"me":[{"add":[{"zipcode":"W1B 4BD"},{"zipcode":"400001"}]}]}

Hope this works for you.