question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC: Extra property on field definition to pass extra metadata

See original GitHub issue

I’m currently adding extra properties to some graphql object field definitions, like the following:

const MutationType = new GraphQLObjectType({
  name: 'Mutation',
  fields: () => ({
    AddSomething: {
      // ... normal field properties
      somethingElse: {},
    }
  }),
})

And then using them later on via the info argument inside some middlewares (using graphql-middleware):

const mutationField = info.schema.getMutationType().getFields()[info.fieldName];
console.log(mutationField.somethingElse);

For more details, see the following medium post: graphql mutation arguments validation using yup


The thing is, this is relying on internal behavior. The following code spreads all properties given to the field: https://github.com/graphql/graphql-js/blob/81719749e01f030cfb3a01a97e7e4bfc534bb08f/src/type/definition.js#L720-L724

Is that something expected to not change? If yes, then no need for any other extra property or for this issue. 😄

But if this is something that can change in future versions, I would love the possibility of having an extra field for that extra metadata.

I’m available to work on adding this, if it’s approved.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:20
  • Comments:28 (17 by maintainers)

github_iconTop GitHub Comments

11reactions
IvanGoncharovcommented, Aug 20, 2019

It took longer than I planned but I finally merged it in #2097 Thanks for patience 🙇 I will try to cut release today/tomorrow

9reactions
IvanGoncharovcommented, Jan 26, 2019

Should we mutate this object later (by using (schema.getType(“typeName”) as GraphQLObjectType).getFields()[“fieldName”].complexity = 5;) or is it safe to rely on …fieldConfig behavior in that case?

@19majkel94 It should work fine as a workaround until we ship an extensions solution however no long-term guarantees afterward.

I will work on adding immutable extensions into types, fields, args and enum values on next week so we will be able to ship it in 14.2.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Defining and Using Metadata with YANG RFC 7952
Defining and Using Metadata with YANG (RFC 7952, August 2016)
Read more >
RFC 7950: The YANG 1.1 Data Modeling Language
1. o Defined the string value of an identityref in XPath expressions (see Section 9.10). o Clarified what unprefixed names mean in leafrefs...
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
Primitive data types in the OAS are based on the types supported by the JSON Schema Specification Wright Draft 00. Note that integer...
Read more >
RFC 9110 - HTTP Semantics
However, it is good practice to send header fields that contain additional control data first, such as Host on requests and Date on ......
Read more >
Working with object metadata - Amazon Simple Storage Service
Name Description Can user modify the value? Date Current date and time. No Content‑Disposition Object presentational information. Yes Content‑Length Object size in bytes. No
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found