From b99929daa5a59c72205702f631bd74428594b40c Mon Sep 17 00:00:00 2001 From: Robins Gupta Date: Sun, 2 Apr 2017 14:30:23 +0530 Subject: [PATCH 1/7] Dynamic Query type methods added. --- .idea/graphql.iml | 8 ++ .idea/modules.xml | 8 ++ .idea/preferred-vcs.xml | 6 + .idea/vcs.xml | 6 + .idea/workspace.xml | 265 ++++++++++++++++++++++++++++++++++++++++ schema.go | 60 +++++++++ 6 files changed, 353 insertions(+) create mode 100644 .idea/graphql.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/preferred-vcs.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/graphql.iml b/.idea/graphql.iml new file mode 100644 index 00000000..c956989b --- /dev/null +++ b/.idea/graphql.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..e443e8a6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/preferred-vcs.xml b/.idea/preferred-vcs.xml new file mode 100644 index 00000000..a45e7e05 --- /dev/null +++ b/.idea/preferred-vcs.xml @@ -0,0 +1,6 @@ + + + + Git + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..bb5486db --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,265 @@ + + + + + + + + + + + + + + + + + Runtime Object type + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/schema.go b/schema.go index f3a4eaff..e2f39c7c 100644 --- a/schema.go +++ b/schema.go @@ -137,6 +137,66 @@ func NewSchema(config SchemaConfig) (Schema, error) { return schema, nil } + +/*func (gq *Schema) Implementation() map[string][]*Object{ + return gq.implementations +}*/ + +//TODO: Edited..Check implementation of interfaces at runtime.. +//Add Implementations at Runtime.. +func (gq *Schema) AddImplementation() error{ + + // Keep track of all implementations by interface name. + if gq.implementations == nil { + gq.implementations = map[string][]*Object{} + } + for _, ttype := range gq.typeMap { + if ttype, ok := ttype.(*Object); ok { + for _, iface := range ttype.Interfaces() { + impls, ok := gq.implementations[iface.Name()] + if impls == nil || !ok { + impls = []*Object{} + } + impls = append(impls, ttype) + gq.implementations[iface.Name()] = impls + } + } + } + + // Enforce correct interface implementations + for _, ttype := range gq.typeMap { + if ttype, ok := ttype.(*Object); ok { + for _, iface := range ttype.Interfaces() { + err := assertObjectImplementsInterface(gq, ttype, iface) + if err != nil { + return err + } + } + } + } + + return nil +} + + +//TODO: Edited. Added to add Types and Interfaces at RunTime only.. +//Append Runtime schema to map.. +func (gq *Schema)AppendType(objectType Type) error { + if objectType.Error() != nil { + return objectType.Error() + } + var err error + gq.typeMap, err = typeMapReducer(gq, gq.typeMap, objectType) + if err != nil { + return err + } + //Now Add interface implementation.. + return gq.AddImplementation() +} + + + + func (gq *Schema) QueryType() *Object { return gq.queryType } From df8169f00b1337c1bf919358b4e1ec39fad9da26 Mon Sep 17 00:00:00 2001 From: Robins Gupta Date: Sun, 2 Apr 2017 14:33:49 +0530 Subject: [PATCH 2/7] Dynamic Query Type method added. --- .idea/workspace.xml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index bb5486db..3a556229 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,10 +1,7 @@ - - - - + - + From 6dd3253d0903d3ec7107a360bcec824158416243 Mon Sep 17 00:00:00 2001 From: Robins Gupta Date: Sun, 2 Apr 2017 14:35:58 +0530 Subject: [PATCH 3/7] Added methods for adding runtime schema. --- .idea/workspace.xml | 34 +++++++++++++++++++++++++++++++--- schema.go | 7 ++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3a556229..c4bff735 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,9 @@ - + + + - + + + + + + + + + + + + @@ -24,6 +37,13 @@ + + + @@ -140,7 +160,7 @@ - + @@ -258,5 +278,13 @@ + + + + + + + + \ No newline at end of file diff --git a/schema.go b/schema.go index df18bd98..715aa16c 100644 --- a/schema.go +++ b/schema.go @@ -145,11 +145,8 @@ func NewSchema(config SchemaConfig) (Schema, error) { } -/*func (gq *Schema) Implementation() map[string][]*Object{ - return gq.implementations -}*/ -//TODO: Edited..Check implementation of interfaces at runtime.. +//Added Check implementation of interfaces at runtime.. //Add Implementations at Runtime.. func (gq *Schema) AddImplementation() error{ @@ -186,7 +183,7 @@ func (gq *Schema) AddImplementation() error{ } -//TODO: Edited. Added to add Types and Interfaces at RunTime only.. +//Edited. Added to add Types and Interfaces at RunTime only.. //Append Runtime schema to map.. func (gq *Schema)AppendType(objectType Type) error { if objectType.Error() != nil { From 360a12451e93397d1bf113300bd8e9a5078b832f Mon Sep 17 00:00:00 2001 From: Robins Gupta Date: Sun, 2 Apr 2017 14:39:00 +0530 Subject: [PATCH 4/7] Added method to add runtime types to existing schema. --- .gitignore | 1 + .idea/graphql.iml | 2 + .idea/libraries/GOPATH__graphql_.xml | 107 +++++++++++++++++++++++++++ .idea/libraries/Go_SDK.xml | 10 +++ .idea/workspace.xml | 35 +++++++-- 5 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 .idea/libraries/GOPATH__graphql_.xml create mode 100644 .idea/libraries/Go_SDK.xml diff --git a/.gitignore b/.gitignore index e43b0f98..3d725761 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +.idea \ No newline at end of file diff --git a/.idea/graphql.iml b/.idea/graphql.iml index c956989b..dcc56f46 100644 --- a/.idea/graphql.iml +++ b/.idea/graphql.iml @@ -4,5 +4,7 @@ + + \ No newline at end of file diff --git a/.idea/libraries/GOPATH__graphql_.xml b/.idea/libraries/GOPATH__graphql_.xml new file mode 100644 index 00000000..9c398a94 --- /dev/null +++ b/.idea/libraries/GOPATH__graphql_.xml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Go_SDK.xml b/.idea/libraries/Go_SDK.xml new file mode 100644 index 00000000..22c27bf0 --- /dev/null +++ b/.idea/libraries/Go_SDK.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c4bff735..6b36486e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,11 @@ - + + + + +