Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: is it possible to include the graphql type in the scalar "serialize" function #7

Open
codecvlt opened this issue Jan 15, 2016 · 2 comments

Comments

@codecvlt
Copy link

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!

@tgriesser
Copy link
Contributor

Not currently, but I've opened a ticket on graphql-js to allow this functionality: graphql/graphql-js#306

@tgriesser
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants