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: TypeGraphQL uses functions to prevent circular dependencies-wouldn't this package's API suffer from the same problem? #22

Closed
capaj opened this issue May 7, 2018 · 7 comments

Comments

@capaj
Copy link
Contributor

capaj commented May 7, 2018

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.
@capaj
Copy link
Contributor Author

capaj commented May 7, 2018

cool, but wait do you contribute here too @19majkel94 ?

@MichalLytek
Copy link

@capaj Nope, I just secretly watch all related projects and sometimes try to help in the name of the open source community 😉

@capaj
Copy link
Contributor Author

capaj commented May 7, 2018

@19majkel94 nice 🥇 I have to say It's a shame you don't work on the same project with @pie6k, because you two would make a great team-both of your libraries have very similar API and design goals. Seems like a waste of time to be working separately. But I guess in such an early stage of graphQL ecosystem more POCs isn't such a bad thing.

@capaj capaj closed this as completed May 7, 2018
@MichalLytek
Copy link

@capaj
I've proposed that a long time ago:
indigotech/graphql-schema-decorator#65 (comment)

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 😄

@capaj
Copy link
Contributor Author

capaj commented May 7, 2018

@19majkel94 great to hear what the difference really is. I can certainly appreciate both approaches-I am sure there are going to be apps well suited to both paradigms. Thanks for all the info! I am considering using one or the other in our API at Looop.co and these are exactly the things I need to know.

@pie6k
Copy link
Collaborator

pie6k commented 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.

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

3 participants