Closed predmond closed 6 years ago
Working on this now. The latest commit on master has the change e955c06ab3257602a36b7f8fae808c1ac634055d and should work now. Please try it out and let me know how it goes.
Just needed to add a data type mapping for this in Substance and update the unit tests. I haven't used SQL databases a lot so I probably missed a lot of data types. If anything was missed or appears to be mapped incorrectly then please feel free to open another issue or even better a pull request. The mappings can be found in the files linked below:
https://github.com/ahmedalhulaibi/substance/blob/master/providers/pgsqlsubstance/pgsqlDataTypeMap.go https://github.com/ahmedalhulaibi/substance/blob/master/providers/mysqlsubstance/mysqlDataTypeMap.go
It still panics. I'm using jsonb
not json
.
I just pushed the new binaries now.
https://github.com/ahmedalhulaibi/graphqlator/releases/tag/v0.3.7-alpha
BTW which database are you using?
postgres
Thanks. Is it still panicking with the latest version?
It still panicked but for a different reason. I only listed one table in the config and it panicked when it couldn't find another table.
panic: assignment to entry in nil map
goroutine 1 [running]:
github.com/ahmedalhulaibi/graphqlator/vendor/github.com/ahmedalhulaibi/substance/substancegen/generators/graphqlgo.Gql.ResolveForeignRefsFunc(0x0, 0x0, 0xc4200ff920, 0xc4200ff950, 0xc4200ff980, 0xc42012a2b0, 0x8, 0xc420246600, 0xe, 0x18, ...)
/home/predmond/src/swarm/go/src/github.com/ahmedalhulaibi/graphqlator/vendor/github.com/ahmedalhulaibi/substance/substancegen/generators/graphqlgo/graphqlgo.go:201 +0xc7c
github.com/ahmedalhulaibi/graphqlator/vendor/github.com/ahmedalhulaibi/substance/substancegen/generators/graphqlgo.Gql.ResolveRelationshipsFunc(0x0, 0x0, 0xc4200ff920, 0xc4200ff950, 0xc4200ff980, 0xc42012a2b0, 0x8, 0xc42001b3e0, 0x27, 0xc420080820, ...)
/home/predmond/src/swarm/go/src/github.com/ahmedalhulaibi/graphqlator/vendor/github.com/ahmedalhulaibi/substance/substancegen/generators/graphqlgo/graphqlgo.go:113 +0x4e4
github.com/ahmedalhulaibi/graphqlator/vendor/github.com/ahmedalhulaibi/substance/substancegen/generators/graphqlgo.Gql.GetObjectTypesFunc(0x0, 0x0, 0xc4200ff920, 0xc4200ff950, 0xc4200ff980, 0xc42012a2b0, 0x8, 0xc42001b3e0, 0x27, 0xc420080820, ...)
/home/predmond/src/swarm/go/src/github.com/ahmedalhulaibi/graphqlator/vendor/github.com/ahmedalhulaibi/substance/substancegen/generators/graphqlgo/graphqlgo.go:83 +0x95b
github.com/ahmedalhulaibi/graphqlator/cmd.glob..func2(0x930480, 0xc42010eb30, 0x0, 0x1)
/home/predmond/src/swarm/go/src/github.com/ahmedalhulaibi/graphqlator/cmd/generate.go:47 +0x1ff
github.com/ahmedalhulaibi/graphqlator/vendor/github.com/spf13/cobra.(*Command).execute(0x930480, 0xc42010eb20, 0x1, 0x1, 0x930480, 0xc42010eb20)
/home/predmond/src/swarm/go/src/github.com/ahmedalhulaibi/graphqlator/vendor/github.com/spf13/cobra/command.go:702 +0x2c6
github.com/ahmedalhulaibi/graphqlator/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x9308c0, 0xc42010eae0, 0xc42005bf70, 0x406094)
/home/predmond/src/swarm/go/src/github.com/ahmedalhulaibi/graphqlator/vendor/github.com/spf13/cobra/command.go:783 +0x30e
github.com/ahmedalhulaibi/graphqlator/vendor/github.com/spf13/cobra.(*Command).Execute(0x9308c0, 0x4, 0xc420087188)
/home/predmond/src/swarm/go/src/github.com/ahmedalhulaibi/graphqlator/vendor/github.com/spf13/cobra/command.go:736 +0x2b
main.main()
/home/predmond/src/swarm/go/src/github.com/ahmedalhulaibi/graphqlator/main.go:15 +0x31
In this case I think printing a warning and skipping would be preferable to panicking.
Oh I see. I have to take a closer look when I work on it tonight but you're right about the cause. it is likely looking for a table that has a foreign reference that is not included in the config file.
Recreated the issue. Thanks for opening this issue, would not have found it otherwise.
Latest release v0.3.9-alpha should address the second panic by logging a warning and skipping. Let me know if it works, and of course if you find another issue please let me know!
For documentation purposes the issue specifically arises when a table is included in graphqlator-pkg.json and there are other tables within the database which are not referenced in graphqlator-pkg.json.
The panic occurred in substance/substancegen/generators/graphqlgo.Gql.ResolveForeignRefsFunc
as a result of attempting to access an element from a map
which did not exist. In this case, the element is a table which had not been loaded into substancegen.
For example a Table Persons is included in graphqlator-pkg.json. In the database there are two other tables Orders and AntiOrders which have a foreign key reference to a column on Persons. This scenario would trigger
Table: Persons
Relationships:
Table Name: AntiOrders
Column Name: PersonID
Ref Table Name: Persons
Ref Col Name: ID
Table Name: Orders
Column Name: PersonID
Ref Table Name: Persons
Ref Col Name: ID
It still panics for me in the same way.
Can you paste the dump?
Nevermind I recreated the error.
I have a resolution but there are bunch of issues with postgres code generation right now. Going to mark postgres code generation as not working as I'm in the process of redesigning the code generation process to use go templates. I will add these conditions to the test cases and make sure it all works out.
Thanks for taking the time here to open the issue and test it out. Hopefully I can get all the fixes in a week or so. Mind if I reach out to you to test it?
When you have some time could you give the latest release a shot?
I tested on our schema but got a panic:
note: the describe command finished (no panic) with the same warnings: