I'm using graphql + mysql + react-apollo and here's one of the graphql type for User
table:
type User {
id: ID!
name: String!
}
My issue with ID scalar type
in graphql
is that it is returned as a string when primary keys are int
in mysql and it has created some type conflicts on the frontend with typescript.
Can I just simply not use ID scalar type at all, given that I have already set a unique identifier with dataIdFromObject
for each object in Apollo Client:
import {InMemoryCache} from 'apollo-cache-inmemory';
const apolloMemoryCache = new InMemoryCache(
{
dataIdFromObject: ({id,__typename}) => {
return __typename+id
}
}
);
const client = new ApolloClient({
link: ApolloLink.from([authLink, httpLink]),
cache: apolloMemoryCache,
});
Would you keep the ID type or just ditch it?