charlieschwabacher / gestalt

Use the GraphQL schema language and a small set of directives to define an API with a PostgreSQL backend declaratively, really quickly, and with a tiny amount of code.
MIT License
207 stars 15 forks source link

node RootQuery is making incorrect SQL calls #8

Closed jacobhausler closed 8 years ago

jacobhausler commented 8 years ago

Hey,

The following query returns a syntax error (the record exists in my db):

query{
  node(id:"0409c1bd-6652-4e31-9f92-24bdf07968ba"){
    ... on User{
            id
            fullName
    }
  }
}

This is the query that is being run by the Database Adapter:

SELECT * FROM 0409c1bd_6652_4e31_9f92_24bdf07968bas WHERE id = $1; [null]

Can you advise how type resolution works with the Node query, and why the query is calling the id as the table name instead of as $1?

charlieschwabacher commented 8 years ago

Hey - the node ids are equal to ${typeName}:${databaseId}, so to get the type and database id it just splits on the colon. This should work:

query{
  node(id:"User:0409c1bd-6652-4e31-9f92-24bdf07968ba"){
    ... on User{
            id
            fullName
    }
  }
}

But this should definitely raise a more descriptive error when the id isn't valid.. going to leave this issue open to track adding that check.

charlieschwabacher commented 8 years ago

added a descriptive error message here