You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the graphql-relay-js library they have a function to declare a GlobalID for a type.
export function globalIdField(
typeName?: ?string,
idFetcher?: (object: any, info: GraphQLResolveInfo) => string
): GraphQLFieldConfig {
return {
name: 'id',
description: 'The ID of an object',
type: new GraphQLNonNull(GraphQLID),
resolve: (obj, args, info) => toGlobalId(
typeName != null ? typeName : info.parentType.name,
idFetcher ? idFetcher(obj, info) : obj.id
)
};
}
This is used by relay to ensure you don't expose raw database ids to the public, and also to determine a node type based on it's id (since the id is hashed along with it's type).
Is there anyway to check the graphql type for an object in the serialize function of a scalar definition, so that i can encode these ID with their appropriate type?
@codecvlt from the comments in the PR I mentioned above, it doesn't look like this will be a possibility, you can check the explanation there for more info.
In the graphql-relay-js library they have a function to declare a GlobalID for a type.
export function globalIdField(
typeName?: ?string,
idFetcher?: (object: any, info: GraphQLResolveInfo) => string
): GraphQLFieldConfig {
return {
name: 'id',
description: 'The ID of an object',
type: new GraphQLNonNull(GraphQLID),
resolve: (obj, args, info) => toGlobalId(
typeName != null ? typeName : info.parentType.name,
idFetcher ? idFetcher(obj, info) : obj.id
)
};
}
This is used by relay to ensure you don't expose raw database ids to the public, and also to determine a node type based on it's id (since the id is hashed along with it's type).
Is there anyway to check the graphql type for an object in the serialize function of a scalar definition, so that i can encode these ID with their appropriate type?
e.g
scalar GlobalID
GlobalID: {
serialize(id, nodeType) {
return toGlobalId(nodeType, id);
}
}
Thanks!
The text was updated successfully, but these errors were encountered: