Skip to content

Commit 72d6fd8

Browse files
authored
Merge pull request #38 from graphql-go/improvements
{executor,extractor}: consolidates executor execute return related types.
2 parents f34263c + 17328c1 commit 72d6fd8

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

executor/executor.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ func New() *Executor {
1818

1919
// ExecuteResult is the result of the execute method.
2020
type ExecuteResult struct {
21-
Result string
21+
// ImplementationIntrospection is the introspection result of a graphql implementation.
22+
ImplementationIntrospection types.ImplementationIntrospection
2223
}
2324

2425
// ExecuteParams is the params of the execute method.
2526
type ExecuteParams struct {
27+
// Implementation is the implementation parameter.
2628
Implementation types.Implementation
2729
}
2830

@@ -32,12 +34,12 @@ func (e *Executor) Execute(params ExecuteParams) (*ExecuteResult, error) {
3234
Query: params.Implementation.Introspection.Query,
3335
}
3436

35-
result, err := e.goExecutor.Run(runParams)
37+
runResult, err := e.goExecutor.Run(runParams)
3638
if err != nil {
3739
return nil, err
3840
}
3941

4042
return &ExecuteResult{
41-
Result: result.Result,
43+
ImplementationIntrospection: runResult.ImplementationIntrospection,
4244
}, nil
4345
}

executor/go.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66

77
"github.com/graphql-go/graphql"
8+
9+
"graphql-go/compatibility-standard-definitions/types"
810
)
911

1012
// Go handles the go execution of a introspection query.
@@ -46,7 +48,8 @@ type RunParams struct {
4648

4749
// RunResult represents the result of the run method.
4850
type RunResult struct {
49-
Result string
51+
// ImplementationIntrospection is the result of an introspection of a graphql implementation.
52+
ImplementationIntrospection types.ImplementationIntrospection
5053
}
5154

5255
// Run runs and returns a given introspection query.
@@ -77,12 +80,22 @@ func (g *Go) Run(params *RunParams) (*RunResult, error) {
7780
return nil, joinedErrs
7881
}
7982

80-
result, err := json.Marshal(doResult)
83+
doResultData, err := json.Marshal(doResult.Data)
8184
if err != nil {
8285
return nil, fmt.Errorf("failed to do marshal: %w", err)
8386
}
8487

88+
introspectionResult := &types.IntrospectionQueryResult{}
89+
90+
if err := json.Unmarshal([]byte(doResultData), introspectionResult); err != nil {
91+
return nil, err
92+
}
93+
94+
implementationIntrospection := types.ImplementationIntrospection{
95+
QueryResult: *introspectionResult,
96+
}
97+
8598
return &RunResult{
86-
Result: string(result),
99+
ImplementationIntrospection: implementationIntrospection,
87100
}, nil
88101
}

extractor/extractor.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ func (e *Extractor) extractImplementation(implementation types.Implementation) (
115115
Query: string(introspectionQuery),
116116
}
117117

118-
if _, err := e.executor.Execute(executor.ExecuteParams{
118+
executeResult, err := e.executor.Execute(executor.ExecuteParams{
119119
Implementation: implementation,
120-
}); err != nil {
120+
})
121+
if err != nil {
121122
return nil, fmt.Errorf("failed to execute: %w", err)
122123
}
123124

124-
return &types.ImplementationIntrospection{}, nil
125+
return &executeResult.ImplementationIntrospection, nil
125126
}
126127

127128
// parseSpec parses and returns the introspection result of the graphql specification

0 commit comments

Comments
 (0)