matthewmueller / matthewmueller/graph.ql

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

Open
#7 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
629
Forks
27
PR merge metrics
No merged PRs in 30d

Description

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!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the GraphQL scalar serialize API and the graphql-relay-js globalIdField example in the issue. Determine whether serialize receives the parent GraphQL type or enough context to encode the ID, and identify the project entry point or tests that would need to demonstrate the behavior. Done means the supported behavior or limitation is established and documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, javascript
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.