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.

Question: TypeGraphQL uses functions to prevent circular dependencies-wouldn't this package's API suffer from the same problem?

See original GitHub issue

the quote from: https://19majkel94.github.io/type-graphql/docs/types-and-fields.html

Why function syntax, not simple { type: Rate } config object? Because this way we solve problems with circular dependencies (e.g. Post <--> User), so it was adopted as a convention. You can use the shorthand syntax @Field(() => Rate) if you want to safe some keystrokes but it might be less readable for others.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
pie6kcommented, May 8, 2018

Thanks @capaj @19majkel94 .

Right, if you’ve got circular dependencies you’d have to use type lazy function like:

import { ObjectType, Field } from 'typegql';

@ObjectType()
class Car {
  @Field({ type: () => Person })
  owner() {
    return db.findPersonByCarId(this.id);
  }
  @Field() id: number;
}

@ObjectType()
class Person {
  @Field() id: number;
  @Field() name: string;
  @Field({ type: () => Car })
  car() {
    return db.findCarByOwnerId(this.id);
  }
}

Note it might be not needed anymore if typescript itself would make reflection metadata lazy in its core.

2reactions
MichalLytekcommented, May 7, 2018

@capaj I’ve proposed that a long time ago: https://github.com/indigotech/graphql-schema-decorator/issues/65#issuecomment-370560844

But since that time our visions have splited - this is what @pie6k said:

image

So I think it’s better when users have an ability to choose between library vs. framework and also the competition makes the development faster 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

MichalLytek/type-graphql - Support for circular references
A workaround exists for graphql js by using a function for a field's resolve ... you can encounter the same issue when you...
Read more >
Frequently Asked Questions - TypeGraphQL
This error occurs when the resolver (query, mutation, field) type is an interface/union and a plain object is returned from it. In this...
Read more >
GraphQL circular dependency - Stack Overflow
According to this article graphQL does somewhat increase issues with circular dependency. The article suggests using extend type for ...
Read more >
GraphQL vs. REST APIs: Why you shouldn't use GraphQL
Cover some scenarios in which using GraphQL could lead to performance issues and problems related to schemas and complex queries.
Read more >
Build a GraphQL Twitter API Clone with TypeScript ... - YouTube
In this video, we will build a clone of the Twitter API, where users can register, follow & unfollow other users, as well...
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