-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export GetGraphqlServer and accept initialized backend (#2243)
Signed-off-by: robert-cronin <[email protected]>
- Loading branch information
1 parent
4939218
commit bc51756
Showing
3 changed files
with
51 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/99designs/gqlgen/graphql/handler" | ||
"github.com/guacsec/guac/pkg/assembler/backends" | ||
"github.com/guacsec/guac/pkg/assembler/graphql/generated" | ||
"github.com/guacsec/guac/pkg/assembler/graphql/resolvers" | ||
) | ||
|
||
func GetGraphqlServer(ctx context.Context, backend backends.Backend) *handler.Server { | ||
topResolver := resolvers.Resolver{Backend: backend} | ||
config := generated.Config{Resolvers: &topResolver} | ||
config.Directives.Filter = resolvers.Filter | ||
srv := handler.NewDefaultServer(generated.NewExecutableSchema(config)) | ||
return srv | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
_ "github.com/guacsec/guac/pkg/assembler/backends/keyvalue" | ||
|
||
"github.com/guacsec/guac/internal/testing/stablememmap" | ||
"github.com/guacsec/guac/pkg/assembler/backends" | ||
) | ||
|
||
func TestGetGraphqlServer(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
store := stablememmap.GetStore() | ||
backend, err := backends.Get("keyvalue", ctx, store) | ||
if err != nil { | ||
t.Errorf("Error getting backend: %v", err) | ||
} | ||
|
||
srv := GetGraphqlServer(ctx, backend) | ||
if srv == nil { | ||
t.Errorf("Expected GetGraphqlServer to return a non-nil server") | ||
} | ||
} |