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.

Due to how extend works we can't replace type fields

See original GitHub issue

So I was given this project a first try since I’m building some sort of boilerplate. I already have a schema, with (most) resolvers in place and I wanted to extend this with mock data. I’m assuming this scenario is probably not the goal for this project, but certainly seems like it can be used for it, and yet it can’t. I can’t replace fields within the existing types since extendSchema from graphqljs seems to complain. In this case what I’d like is to leave the schema as is, but replace the resolver instead.

Example: Original schema:

type User {
  id: ID!
  firstName: String
  lastName: String
}

Our fake schema in extend mode:

extend type User {
  firstName: String @fake(type: firstName)
  lastName: String @fake(type: lastName)
}

I would have expected the above syntax to work, and the resolver within it to return me the fake fields. I feel like I’m missing something obvious but if this isn’t supported I think it should. I’d be able to help if you can point me in the right direction.

EDIT: I’ve done something like this in the past with addMockFunctionsToSchema from graphql-tools but obviously, that one lacks the Faker integration, and it’s also hard to do proper relay connections in there. Maybe we could find a way to use it here as a last resort, but I think custom resolvers after leaving the schema in place should be the way to go.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:8
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

15reactions
IvanGoncharovcommented, May 6, 2019

@ahmedlhanafy Not ATM, it’s just a proposed solution. I will try to find time to implement it this month

12reactions
hotsezuscommented, Mar 15, 2021

I made NPM module based on my PR which enables fields overriding. If you need this feature in main module, you can subscribe to my PR’s notifications and use my fork-module until it gets merged.

https://www.npmjs.com/package/@proscom/graphql-faker

Read more comments on GitHub >

github_iconTop Results From Across the Web

Due to how extend works we can't replace type fields #17
I can't replace fields within the existing types since extendSchema from graphqljs seems to complain. In this case what I'd like is to...
Read more >
Extending Types - Hot Chocolate
Extending Types. Type extensions allow us to add, remove or replace fields on existing types, without necessarily needing access to these types.
Read more >
Extending object-like types with interfaces in TypeScript
Let's dive into exploring the various characteristics of interfaces and how we might better leverage them in our programs. Jump ahead:.
Read more >
Overriding interface property type defined in Typescript d.ts file
I use a method that first filters the fields and then combines them. reference Exclude property from type interface A { x: string...
Read more >
Reusing code with extends | Looker - Google Cloud
Overview · Write DRY (don't repeat yourself) code, so that you can define things in just one place, making your code more consistent...
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