hasura / go-graphql-client

Package graphql provides a GraphQL client implementation.
MIT License
395 stars 91 forks source link

UUID Error #105

Closed bete7512 closed 1 year ago

bete7512 commented 1 year ago

` func InsertUserPassword(userid, password string) (string,error){ client := config.GraphqlClient() parsedUserId, := uuid.Parse(user_id)

variables := map[string]interface{}{     
    "user_id": parsedUserId.String(),     
    "password": password,       
}

fmt.Println("Type Of UUID",reflect.TypeOf(variables["user_id"]))
fmt.Println("Type Of String",reflect.TypeOf(variables["password"]))
var response mutation         

err := client.Mutate(context.Background(),&response, variables)
if err != nil {   
    fmt.Println("An error occurred:", err)   
    return "", errors.New("error fetching user data")
}
responseJSON, _ := json.Marshal(response)           
fmt.Println(string(responseJSON))         
return "",nil

} `

but it throws Message: variable 'user_id' is declared as 'String!', but used where 'uuid!' is expected, Locations: [], Extensions: map[code:validation-failed path:$.selectionSet.update_authentications_by_pk.args.pk_columns.user_id] I tried by removing String()

hgiasac commented 1 year ago

Hi,

You need to define type uuid alias so the library can infer the GraphQL type.

type uuid string
variables := map[string]interface{}{     
    "user_id": uuid(parsedUserId.String()),     
    "password": password,       
}
bete7512 commented 1 year ago

Okay Thanks very Good Answer it works fine