Comments (5)
Hi, I found out what was causing the problem, the result type of users needs to be the same as the type its querying i.e [UserProfiles]
.
Moreover, I recommend as defined in docs to use the @generate
directive as it adds limit,offset, ordering and automatic filtering.
Note: that this library is really in the start and I still need to add support for adding more complex filter support.
GraphQL schema I used to check your problem.
scalar Time
type Country {
id: String
name: String
}
type UserProfile @generateFilterInput(name: "UserProfileFilterInput") @tableName(name: "myapp.user_profile") {
userID: ID! @sqlRelation(relationType: ONE_TO_ONE, baseTable: "myapp_private.user_account", refTable: "janaez.user_profile", fields: ["id"], references: ["user_id"])
firstname: String
lastname: String
displayname: String!
createdAt: Time
updatedAt: Time
nationality: Country @sqlRelation(relationType: ONE_TO_ONE, baseTable: "myapp.country", refTable: "myapp.user_profile", fields: ["id"], references: ["nationality_id"])
}
type Query @generate {
# UserProfile
users: [UserProfile!]!
}
Hope this helps, if you like this project, feel free to contribute, ill be more than happy to merge features/get feature requests you might want
from fastgql.
Hi @aenawi, thanks for trying fastgql, is super early lib as you can see it doesn't have tests.
I will take a look why the directive didn't work correctly and get back to you.
from fastgql.
Thanks, yes I've noticed no tests available, just got curious to give it a try ;) I like when smart developers think in different ways.
Anyways, so far these are the results from what I understood:
First, after making the changes you mentioned above, yes the query got corrected, but still I've received this error from GraphQL:
{
"errors": [
{
"message": "ERROR: relation \"myapp.user_profile\" does not exist (SQLSTATE 42P01)",
"path": [
"users"
]
}
],
"data": null
}
and when I debugged the Users resolver in (shema.fastgql.go) file, I've noticed that sql.NewBuilder created the following query which looks a bit confusing and it didn't accept "myapp.user_profile" (with quotes) in the sql statement! To test it I've copied the statement and ran it under PgAdmin console and "myapp.user_profile" (with quotes) was highlighted as an error. I removed the quotes and it did accept it but couldn't continue because of the rest LEFT JOIN LATERAL (FROM "userID") - that which I don't understand at this stage!
SELECT
"duqtxi"."userID" AS "userID",
"zpehps"."firstname" AS "firstname",
"zpehps"."lastname" AS "lastname",
"zpehps"."displayname" AS "displayname",
"zpehps"."createdAt" AS "createdAt",
"zpehps"."updatedAt" AS "updatedAt",
"zyfjlr"."nationality" AS "nationality"
FROM "myapp.user_profile" AS "zpehps"
LEFT JOIN LATERAL (
SELECT jsonb_build_object() AS "userID"
FROM "userID" AS "duqtxi"
WHERE zpehps.id = duqtxi.user_id
) AS "duqtxi" ON true
LEFT JOIN LATERAL (
SELECT jsonb_build_object('id', "zyfjlr"."id", 'name', "zyfjlr"."name") AS "nationality" FROM "nationality" AS "zyfjlr"
WHERE zpehps.nationality_id = zyfjlr.id
) AS "zyfjlr" ON true
LIMIT $1
another thing I've noticed from last LEFT JOIN LATERAL, why the name of the table in the FROM showing (nationality) and not (country) since Country was the type defined in the GraphQL schema for UserProfile!
Any ways, I stopped at the confusing part where the Executor.Query is not able to execute the statement built using sql.NewBuilde, b'cos of all those quotes and aliases! Do I need to reconfigure my PostgrSQL DB or something?!
I think I should wait for a while until you create some more examples, or add unit tests.
Thank you for all your efforts
from fastgql.
Hi sorry for taking so long to reply, I added a argument to the @tableName
directive, this should solve this error "message": "ERROR: relation \"myapp.user_profile\" does not exist (SQLSTATE 42P01)",
.
Started adding tests as well so hopefully ill get around to stabilizing the code some more and test more usecases.
from fastgql.
Fixed in #18 the LEFT JOIN LATERAL
so the FROM should be based on the type rather than the selection. (it will use the type name if there is not @tablename directive on that type)
from fastgql.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastgql.