graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Add ability to match uuid to String when creating remote schema relationship

Open NikPaushkin opened this issue 4 years ago • 8 comments

Right now if I have a column with uuid type and I want to pass its value as an argument to remote schema's String field, I'm getting an error

Cannot validate remote relationship because expected type "String", but got "uuid"

But it's technically possible to match uuid to String, because any uuid can be converted to string. Moreover, String is a superclass for any other GraphQL type, so value from any Postgre field could be matched to remote schema's String like this.

NikPaushkin avatar Jul 29 '20 19:07 NikPaushkin

on the same note matching postgres text columns to graphql ID should be possible as well :)

aaronhayes avatar Jul 30 '20 23:07 aaronhayes

Any workaround suggested for uuid -> string mapping?

abpa avatar Sep 23 '20 19:09 abpa

This is a major showstopper for us, is there any workaround? Or perhaps someone from the graphql-engine project can point us to where something like a mapper could be implemented so that the OpenSource community can put up a PR perhaps? I'll be more than glad to take a stab at it!

danazkari avatar Dec 10 '20 16:12 danazkari

This is a major showstopper for us, is there any workaround?

@danazkari Personally, I've migrated Hasura's table from uuid to String, still using it as a primary key.

NikPaushkin avatar Dec 10 '20 16:12 NikPaushkin

I made it work using a custom GraphQL type named 'uuid':

const typeDefs = gql`
  scalar uuid

  type Query {
    user(id: uuid!): User
  }
`;

const uuidScalarType = new GraphQLScalarType({
  name: 'uuid',
  description: 'Faux-UUID type to fool Hasura',
  serialize(value) {
    return value;
  },
  parseValue(value) {
    return value;
  },
  parseLiteral(ast) {
    return (ast as any).value;
  }
});

const resolvers = {
  uuid: uuidScalarType,
  Query: {
    user: (parent, args) => {
      ...
    }
  }
}

DDoerner avatar Feb 25 '21 16:02 DDoerner

I made it work using a custom GraphQL type named 'uuid':

That's good if you can easily change your remote schema. Can't be done quickly in our case, for example https://github.com/puzl-ee/qube

NikPaushkin avatar Feb 25 '21 16:02 NikPaushkin

I made it work using a custom GraphQL type named 'uuid':

That's good if you can easily change your remote schema. Can't be done quickly in our case, for example https://github.com/puzl-ee/qube

That's true. Just wanted to add that possibility for those that can and might stumble over this issue. I'd also prefer your suggested solution over my workaround.

DDoerner avatar Feb 25 '21 16:02 DDoerner

Any updates on this @0x777 ?

SharmaPawan11 avatar Sep 09 '22 16:09 SharmaPawan11