0

i feel like im going crazy here. spent the last couple hours searching and there is not one single official or complete source of information on this topic. all that i have found are vague 10 line of code representations of how relationships would look in the typedefs but no implementation details anywhere!

i thought this would be a very common use case in graphql. why is nobody talking about it?

are there any resources you can recommend on implementing o2m and m2m relationships? am i thinking of this wrong and this isnt something graphql supports?

here is the implementation i am stuck on (i believe caused by circular references).

vampiire
  • 1,111
  • 2
  • 15
  • 27
  • If you give examples of o2m and m2m queries I can give you examples of how to implement graphql schema for handling them. – zoran404 May 03 '18 at 21:31
  • do you want me to write them here or would you mind joining me on discord / hangouts? i have a simple (2 types) application that i am trying to relate. everything works until i implement the relationship – vampiire May 03 '18 at 21:35
  • You can post it in your question, so others can see what I'm referencing – zoran404 May 03 '18 at 21:37
  • check out zero-to-graphql. Quite a minimal example in different languages, but includes DB, schema and everything. Also demonstrates many-to-many relations https://github.com/steveluscher/zero-to-graphql – tenshi May 03 '18 at 21:37
  • keep running into what i believe to be a circular reference issue. have been at it for about 10 hours total now. tried everything i could find online. eventually backed up to start searching "relationship modeling in graphql" for a couple hours. and here i am – vampiire May 03 '18 at 21:37
  • sure. i actually posted it earlier and didnt get any votes. i will add the link now – vampiire May 03 '18 at 21:38
  • zero-to-graphql (referenced above) has a pretty nice example, probably should check it out – zoran404 May 03 '18 at 21:40
  • yep got it open already. taking a look. do you feel that conversation about modeling relationships in graphql is a little sparse? am i thinking about this the right way? – vampiire May 03 '18 at 21:41
  • that github is for a single Person Type. there are no relationships in it (at least the node dir) – vampiire May 03 '18 at 21:43
  • I would agree, the material on this subject is quite sparse at the moment. I get a lot of questions about it. zero-to-graphql helps a lot in this respect. Also "How to GraphQL" has info on this as well (here is a scala-based example): https://www.howtographql.com/graphql-scala/7-relations/ – tenshi May 03 '18 at 21:46
  • That's true, there is only a single person type, but it is a recursive type. so there is a relation between person and it's friends (which are of the same type): https://github.com/steveluscher/zero-to-graphql/blob/master/zero-node/schema.js#L63-L68 – tenshi May 03 '18 at 21:49
  • right. but the issue im having is caused by circular references / dependencies. modular type defs for organization. while the Person example covers an aspect of relationships it doesnt help with the circular issue because its all internal to the type. – vampiire May 03 '18 at 21:53
  • Also, if scala is your thing, I there is another example with 2 different types: categories and products and different relation types between these https://sangria-graphql.org/learn/#high-level-fetch-api – tenshi May 03 '18 at 21:54
  • thanks but i havent worked with scala. the logic makes sense in any language the syntax (graphql js in this case) im missing. – vampiire May 03 '18 at 21:55

1 Answers1

0

i couldnt get an answer to either of my questions. so i figured it out myself and documented the solution through about 20 commits of refactoring. you can see my original question that led me to seeking relationship modeling resources. i answered the question and gave details and links to the refactor.

before someone edits this answer out i believe it does count as an answer. i provided a resource for someone seeking to model relationships in graphql.

vampiire
  • 1,111
  • 2
  • 15
  • 27