Postgraphile: How to query through join relations when relation is type UUID

Created on 4 Oct 2019  ยท  10Comments  ยท  Source: graphile/postgraphile

I'm submitting a ...

  • [ ] bug report
  • [ ] feature request
  • [X] question

PostGraphile version: 4.2.0

Hello, I am looking to solve what I believe should be a simple use case that I have not found documented in several years. #220 references the base to my question, but it is from 2016 and does not include UUID.

When attempting to implement that solution I receive the error "fieldNameId" must not have a selection since type "UUID" has no subfields., which is correct. TypeORM is the ORM used.

To reiterate from #220, this syntax is ideal:

{
  postById(id: 1) {
    personByAuthorId {
      firstName
      lastName
    }
  }
}

But cannot be done with type UUID.

Please let me know if you have any advice on this issue.

Thank you. Love your product โค๏ธI do plan to donate when I have found success with this business.

โ” question

All 10 comments

I'm not sure I quite follow. Here's what I did to try and reproduce your issue:

benjie@Benjie-Box:~$ createdb issue1162
benjie@Benjie-Box:~$ psql issue1162
psql (11.5 (Ubuntu 11.5-1.pgdg18.04+1))
Type "help" for help.

[issue1162] # create extension pgcrypto;
CREATE EXTENSION
Time: 8.514 ms
[issue1162] # create table people(id uuid primary key default gen_random_uuid(), first_name text not null);
CREATE TABLE
Time: 14.028 ms
[issue1162] # create table posts(id serial primary key, author_id uuid not null references people);
CREATE TABLE
Time: 12.083 ms
[issue1162] # insert into people(first_name) values ('Benjie');
INSERT 0 1
Time: 7.879 ms
[issue1162] # select * from people;
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  id                  โ”‚ first_name โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 292ad2f5-759f-4f06-a2d4-3980ef3254ae โ”‚ Benjie     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
(1 row)

Time: 7.082 ms
[issue1162] # insert into posts (author_id) values ('292ad2f5-759f-4f06-a2d4-3980ef3254ae');
INSERT 0 1
Time: 9.022 ms
[issue1162] # select * from posts;
โ”Œโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ id โ”‚              author_id               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  1 โ”‚ 292ad2f5-759f-4f06-a2d4-3980ef3254ae โ”‚
โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
(1 row)                                                                                                                                                                                               

Time: 0.204 ms                                                                                                                                                                                        
[issue1162] # \q                                                                                                                                                                                      
benjie@Benjie-Box:~$ npx postgraphile -c issue1162

PostGraphile v4.4.3 server listening on port 5000 ๐Ÿš€                                                                                                                                                  

  โ€ฃ GraphQL API:         http://localhost:5000/graphql                                                                                                                                                
  โ€ฃ GraphiQL GUI/IDE:    http://localhost:5000/graphiql (enhance with '--enhance-graphiql')                                                                                                           
  โ€ฃ Postgres connection: postgres:///issue1162                                                                                                                                                        
  โ€ฃ Postgres schema(s):  public                                                                                                                                                                       
  โ€ฃ Documentation:       https://graphile.org/postgraphile/introduction/                                                                                                                              
  โ€ฃ Join Mark Rapoza in supporting PostGraphile development: https://graphile.org/sponsor/                                                                                                            

* * *                                                                                                                                                                                                 

0 error(s) in 29.28ms :: query IntrospectionQuery { __schema { queryType { name } mutationType { name } subscriptionType { name } types { ...FullType } directives { name description locations args { ...InputValue } } } } fragment FullType on __Type { kind name description fields(includeDeprecated: true) { name description args { ...InputValue } type { ...TypeRef } isDeprecated deprecationReason } inputFields { ...InputValue } interfaces { ...TypeRef } enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason } possibleTypes { ...TypeRef } } fragment InputValue on __InputValue { name description type { ...TypeRef } defaultValue } fragment TypeRef on __Type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } }                                                                                                                                          
0 error(s) in 8.29ms :: { postById(id: 1) { personByAuthorId { id firstName } } }
{
  postById(id:1) {
    personByAuthorId{
      id
      firstName
    }
  }
}
{
  "data": {
    "postById": {
      "personByAuthorId": {
        "id": "292ad2f5-759f-4f06-a2d4-3980ef3254ae",
        "firstName": "Benjie"
      }
    }
  }
}

Screenshot_20191004_095148

[semi-automated message] Thanks for your question; hopefully we're well on the way to helping you solve your issue. This doesn't currently seem to be a bug in the library so I'm going to close the issue, but please feel free to keep requesting help below and if it does turn out to be a bug we can definitely re-open it ๐Ÿ‘

You can also ask for help in the #help-and-support channel in our Discord chat.

Thank you Benji! I had just been using improper syntax; I am still learning the graphql language. Your example showed me the err of my ways.

I appreciate you taking the time so quickly to answer my question.

Glad you got it sorted ๐Ÿ‘ Are you able to explain what you did previously that misled you? Were you using GraphiQL? It would be really helpful for me to understand, so I can help others more effectively.

Apologies, I spoke too soon after reading your example. I should have used my own code instead of the docs code as I did not initially realize that they were using the findById function instead of the property name, so that was one lesson gained but not my full problem.

Here better outlines my situation. I am trying to associate two kinds of location to a user, where they are from (origin) and where they live now (resident).

This happens when attempting to add a location by the origin field:

Screen Shot 2019-10-10 at 9 02 28 PM

Screen Shot 2019-10-10 at 9 05 24 PM

Screen Shot 2019-10-10 at 8 59 55 PM

User and Location are joined on a one-to-one relation:

@OneToOne(type => Location)
@JoinColumn()
originLocation: Location;

Thank you for your insight.

We don't have nested mutations built in; I believe there's a plugin for it, but I'd advise the use of Custom Mutations instead.

Thanks for the advice. Could you please take that a step further and explain why the plugin is not recommended over custom mutations?

I see your documentation for custom mutations here: https://www.graphile.org/postgraphile/custom-mutations/

There are likely enough similar scenarios in my app to where I would prefer to have a method rather than have to write individual methods for each if I can. Ideally I would like to either have nested mutations or a mutation that has a sequence of functions in it that I can use the return of one farther down the chain, if possible. (like return from A and B create the many-to-many values for operation C in the mutation).

Trying to set good habits from the start and get my process down for mutations. I have a list of different situations I am looking to get a method for. This is one.

Thank you for taking the time to reply.

Here's some further reading: https://medium.com/@__xuorig__/graphql-mutation-design-anemic-mutations-dd107ba70496

I believe that GraphQL mutations should be atomic and use-case focussed rather than trying to achieve everything with a large, unwieldy, generic API much of which you will never use.

Thank you. That was very helpful. I now feel more equipped to make good decisions.

Is that the case with many of the community packages listed? Otherwise they would be included by default I assume. I plan on experimenting with the many-to-many one.

Yes. Actually I'm not happy that PostGraphile's condition and orderBy fields are so heavily populated either; I'd prefer they were thinned down too (hence --no-ignore-indexes). That said, for some people's schemas adding this flexibility is the right tradeoff and many people love these fully featured schemas so I plan to continue supporting them via plugins, just not in core.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

safaiyeh picture safaiyeh  ยท  3Comments

marshall007 picture marshall007  ยท  3Comments

outsidenote picture outsidenote  ยท  4Comments

srghma picture srghma  ยท  3Comments

james-ff picture james-ff  ยท  4Comments