-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working implementation of visitor
and printer
#10
Conversation
- Still raw. It does not have a way to resolve fields yet. - At least `GraphQL()` can run without panicking. - Added one `executor` test from `graphql-js` while figuring out how to resolve a GraphQLSchema - Will work on GraphQL types/models first
- Still raw. It does not have a way to resolve fields yet. - At least `GraphQL()` can run without panicking. - Added one `executor` test from `graphql-js` while figuring out how to resolve a GraphQLSchema - Will work on GraphQL types/models first
* master:
* master: Fixed `graphQLError` to use `graphql-go/language/ast` instead of `go/ast` Updated file organization for `ast` packages
…tring) - Passed `TestBasicGraphQLExample` (hello world)
- `GraphQLInt` - `GraphQLString` - `GraphQLFloat` - `GraphQLBoolean` - `GraphQLID`
- `GraphQLInt` - `GraphQLString` - `GraphQLFloat` - `GraphQLBoolean` - `GraphQLID`
…cutor.ExecuteParams.Root: map[string]interface{}` - Resolve function: `GraphQLFieldResolveFn: func(p GQLFRParams) interface{}` - Fefault resolveFn currently can automatically resolve fields with values (e.g. `string` etc) and functions with `func() interface{}` signature) - Currently unable to resolve nested fields - `types/*.go` is WIP, will need to be cleaned up and ensure that all type definitions are implemented Notes: - Golang doesn't quite like variables that refers to itself at initialisation ```go // initialisation loop error var __Type = { Type: __Type } ``` Currently have a temporary workaround `__setTypesFor__Type`, but exploring other options to allow user to define `GraphQLObjectTypes` that refers to itself (cyclic ref). One option: `GraphQLObjectTypes.AddFieldConfig(fieldName string, fieldConfig *GraphQLFieldConfig)`
…tesArbritraryCode` test - Requires code clean up - `types` package is still not completed - TODO next: port `executor` tests
- Ported 7/16 tests - Passed 6/7 tests
- Ported 16/16 tests - Passed 12/16 tests - Failed 3/16 - TestCorrectlyThreadsArguments - TestDoesNotIncludeArgumentsThatWereNotSet - TestFailsWhenAnIsTypeOfCheckIsNotMet - Skipped 1/16 - TestCorrectFieldOrderingDespiteExecutionOrder - Golang maps are unordered (order is non-deterministic & random)
* fork/master: update source.NewSource to receive source pointer mark Parser as done 🌟 & add language related todos
- Passed 14/16 - Failed 1/16 - Skipped 1/6
…phql_test.go` tests - No failing tests (Passed 49, Skipped 1) - Filled up `StarWarsSchema` implementation - Updated `graphql_test.go` expected result structure - Might need to rethink GraphQLResult? The resultant data structure isn't as concise as JSON or JS Object - Maybe can utilise `json/encoding` package - Can discuss about re-looking at the `grapql-go` API, to make it much more easier and pleasant to use - For e.g.: see `sangria-graphql` (Scala implementation of `graphaql`
- Basic skeleton for `executor` basically done - Need to port more tests - Need to port more types - Removed previously added `SetName()` interface, not required
- Re-organized `executor.go` to match `graphql-js` for easy maintenance
- Used `GraphQLObjectType.AddFieldConfig()` instead
- Ported from `execution/__tests__/executor_schema.js` - Updated GraphQLResult return by not nesting GraphQLResult within GraphQLResult - Flattened GraphQLResult.Data and appended all errors into GraphQLResult.Errors
- Ported from `execution/__tests__/abstract.js`
- Ported from `execution/__tests__/directives.js` - Fixed a couple of parser and executor bugs
- Ported from `execution/__tests__/lists.js` - Mark 2 tests as `skipped`/TODO - `TestListsNonNullListOfNonNullFuncReturnsNull` `TestListsNonNullListOfNonNullObjectsReturnsNull` ] - Fixed `location.GetLocation()` bug when source is nil
- Ported from `execution/__tests__/variables.js` - Mark 11 tests as `skipped`, - waiting to implement `print()` and `visit()` - needed to walk through ast tree to print useful error stack - other than inaccurate error message, behaviour work as expected - Added `GetValue() interface{}` method to `ast.Value` interface - Will be needed in other parts of the library anyway - Implemented `GetValue()` for structs that implement `ast.Value`
- Ported from `execution/__tests__/nonnull.js` - Some tests are marked as `skipped`, pending a test to set equality for errors slice
- Ported from `execution/__tests__/mutations.js` - All passed - Updated `defaultResolveFn` to automatically resolve struct fields - Will use `json` struct tags to map GraphQLObjectType field with golang Struct field
…ted default ResolverFn - This commit will be a useful diff to see how to use `json` tags to resolve structs automatically by default - Note that `blogAuthor` objectType's `pic` field still has to define its own resolve function because the struct field is a function, not a scalar
- Ported from `execution/__tests__/union-interface.js` - All passed - Implemented some of the required `resolveFn` in introspective types. This completes porting all `executor` tests from `graphql-js`
- Ported all 6 tests from `graphql-js` - 5 pass, 1 skip due to partial pass - Possibly issue with `parser`. Need to fully port all `parser` tests
- Minor error with the QueryDocumentKeys key map - All test pass
```go const ( ActionNoChange ActionBreak ActionRemove ActionUpdate ) ```
…e{}` instead of ast.Node
- Passed all `graphql-js` tests The `visitor` takes in an `ast.Node` and returns `interface{}` which usually is in a form of `map[string]interface{}` The `printer` uses `visitor` to traverse the AST tree and reduce it into a `graphql` query string.
- Unmarked related tests as `skipped` and passed
- Ported from `language/__tests__/schema-printer.js`
- Ported from `language/__tests__/schema-parser.js`
- Removed unused helper functions and re-organized
- But we'll leave `printer` to accept ast.Node only - Since `visitor` can panic, add a fallback to `printer`. Try to minimise runtime error wherever we can.
- Remove unused structs - Set `action string` to `ActionNoChange` as default behaviour for visit funds (empty string)
…behaviour is skipping traversal of sub-tree)
Thanks for even taking the time to look into this 👍🏻 If you want to feel more comfortable and make some changes to my PRs directly, you can create a separate branch ( You can then mess around with it without worrying about committing too much to my PRs. And once you feel comfortable with the state of the |
Thanks for feedback @sogko 👍 , I think we should keep going forward to merging directly to master. We have good quantity of test covering lib which give us enough confidence to do so, besides that I am going to add converge with coveralls.io so I think we are fine. |
Working implementation of `visitor` and `printer`
Merge latest changes from HEAD
Built upon PR #8
Details
visitor
visitor
is used / will be used byprinter
andvalidator
graphql-js
visit()Enter
function when entering a node and visitor'sLeave
function when leaving a nodetype VisitFunc func(p VisitFuncParams) (action string, result interface{})
action string
defines the behaviour of the visit function upon returnconst visitor.ActionNoChange
result interface{}
returnedconst visitor.ActionBreak
result interface{}
returnedconst visitor.ActionSkip
result interface{}
returnedconst visitor.ActionUpdate
result interface{}
. Returnresult = nil
to remove node.printer's printDocASTReducer
for working usage ofvisitor
printer
printer
is used to transform/reduce anast.Node
into astring
.visitor
and pre-definedvisitor.VisitorOptions
to traverse AST and reduce each node to a string (printDocASTReducer
)parser
(which transformsstring
into anast.Node
)Misc
language/parser/schema_parser_test.go
test to complete port of allgraphql-js/language/__tests__/*
testsTest