Skip to content

Commit

Permalink
SDL Support (#503)
Browse files Browse the repository at this point in the history
* Quick sketch of DSL using blueprint insertion

* append -> add

* Setup utilities for blueprint schema editing

* Change some naming

* import_types, import_fields

* Fancy imports, separate macro testing

* Working @desc for object and field

* Start on experimental schema module

* update new tests in light of the switch in master from ExSpec to ExUnit

* remove a bunch of warnings

* resolver_ast => middleware

* improve schema compile time

* remove module attribute literal

* tests all compile now

* remove warnings

* experimental field and object tests passing

* middleware test green

* import types fix

* types => schema_definitions

* use the schema definition

* fix experimental field and type imports

* formatting

* fix tests

* move tests to a normal spot

* sketch beginnings of schema compilation

* fix formatting

* houston we have lift off

* convert experimental to real

* renaming

* project compiles now

* move a bunch of stuff over from regular notation

* tests compile

* still haven't figured out pre commit hooks

* ok now they compile, 543 failures

* mildly working type imports

* formatting

* tests can compile with fewer commnents

* formatting

* formatting

* have the string scalar built directly into the test schema and have no imports for now

* formatting

* use the serialize in the type

* add scala serialize module

* green test

* formatting

* expose parse function

* use parse from the module passed in

* test parse instead

* arg building

* remove logging

* collect module parse from module

* add function to schema module for parsing

* use parser from schema module to consume items

* import default builtins again

* formatting

* Fix Memory Explosion (#570)

* nuke literal after normalization to prevent 2^n memory growth

* improved tactic where we distinguish raw values as separate structs

* more green

* now the fun bit

* various improvements to the validation tests

* so close

* all green

* backwards compatible not/1 syntax

* cleanup debug stuff

* notes

* minor cleanup

* changelog fix

* __absinthe_function__

* formatting

* temporary default middleware application

* non null handling

* remove old files

* implement interface implementors function

* better complexity handling

* handle non null args

* [WIP] Add import_sdl  (#596)

* Basic SDL objects w/ fields

* Tweak test wording

* Work towards SDL descriptions support

* New lexer, SDL descriptions

* Working on column count

* Working column for block values

* Parser support for column numbering

* More work on lexer fixes

* Fix ... and boolean tokens

* Updates for column locations in tests

* Fill in missing column numbers

* meta support

* minor refactor

* col test

* significant support for keyword based fields

* record resolve type

* comboing non null and list of should work now

* mark some probably irrelevant tests pending

* formatting

* working Type.Interface.member?

* formatting

* handle transitive imports

* interfaces/1 macro

* ensure fields get metadata

* import directives

* reintroduce useful schema functions

* warning cleanup

* working enum types

* fix test

* working unions

* default values

* more stuff

* some subscriptions work

* adjust columns

* schema.types => schema.type_definitions

* directives work now

* update test for type -> type_definitions change

* deprecation works properly

* break apart tests some

* a lot more introspection passing

* use accumulate for put attr

* handle desc on enum values:

* handle field imports

* more explanation

* getting close

* remove antiquated build functions

* we should still be using the directives key for this stuff

* sort type suggestions

* updated travis def

* handle looking up functions on introspection types

* green tests yo

* updated travis

* Convert integration tests to standard (#600)

* Convert integration tests to standard

* Fix parser error line/column reporting

* Don't discard line/col info in some tokens

* Fix operation type line/col

* Fix remaining integration tests

* Fix nimble_parsec dep

* formatting

* Revert "formatting"

This reverts commit dd01c7a.

* deal with deprecation warnings

* Sdl resolvers (#606)

* Add modify/1 hook, move pipeline, tweak tests

* formatting and use type references properly

* green simple test

* Support schema decoration

* Use decorations/2

* Add :resolve decoration

* Fix test name

* Add schema compilation error checking to pipeline

* Move SourceLocation from Blueprint.Document to Blueprint

* Remove unused module attribute

* Add :source_location to Blueprint.Schema structs, support in Draft

* Split Type.built_in_module?/1

We're already Module.split/1'ing, so we can use
Module.concat/1 vs Module.safe_concat/1.

* Add module tracking to InputValueDefinition

* Set identifier for InputValueDefinition

* InputValueDefinition -> Type.Argument w/ desc

* Track modules for enum values

* Fix test breakage due to code fix

* Use stuttering pre-walk, test describing args

* Remove module attribute debris

* formatting

* middleware renaming

* green tests

* use middleware_ref consistently

* don't do it for nil  refs

* add back in the struct attrs for functions

* move the functions back into the types

* unify middleware expansion

* handle functions more generically, and inline them when possible

* break out building the types from compiling them

* improved function inlining

* remove warning

* working subscription tests
  • Loading branch information
benwilson512 authored Sep 20, 2018
1 parent 28848fd commit 01be95b
Show file tree
Hide file tree
Showing 420 changed files with 5,947 additions and 4,473 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: elixir
elixir:
- 1.4.5
- 1.5.1
- 1.6.6
- 1.7.3
notifications:
recipients:
- [email protected]
- [email protected]
otp_release:
- 19.2
- 20.0
- 21.0
script: "MIX_ENV=test mix local.hex --force && MIX_ENV=test mix do deps.get, test"
2 changes: 1 addition & 1 deletion lib/absinthe.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule Absinthe do

@type result_error_t ::
%{message: String.t()}
| %{message: String.t(), locations: [%{line: integer, column: integer}]}
| %{message: String.t(), locations: [%{line: pos_integer, column: integer}]}

@type result_t ::
%{data: nil | result_selection_t}
Expand Down
17 changes: 15 additions & 2 deletions lib/absinthe/blueprint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ defmodule Absinthe.Blueprint do
alias __MODULE__

defstruct operations: [],
types: [],
directives: [],
fragments: [],
name: nil,
schema_definitions: [],
schema: nil,
adapter: nil,
# Added by phases
Expand All @@ -24,7 +24,7 @@ defmodule Absinthe.Blueprint do

@type t :: %__MODULE__{
operations: [Blueprint.Document.Operation.t()],
types: [Blueprint.Schema.t()],
schema_definitions: [Blueprint.Schema.t()],
directives: [Blueprint.Schema.DirectiveDefinition.t()],
name: nil | String.t(),
fragments: [Blueprint.Document.Fragment.Named.t()],
Expand Down Expand Up @@ -80,6 +80,19 @@ defmodule Absinthe.Blueprint do
found
end

@doc false
# This is largely a debugging tool which replaces `schema_node` struct values
# with just the type identifier, rendering the blueprint tree much easier to read
def __compress__(blueprint) do
prewalk(blueprint, fn
%{schema_node: %{identifier: id}} = node ->
%{node | schema_node: id}

node ->
node
end)
end

@spec fragment(t, String.t()) :: nil | Blueprint.Document.Fragment.Named.t()
def fragment(blueprint, name) do
Enum.find(blueprint.fragments, &(&1.name == name))
Expand Down
12 changes: 4 additions & 8 deletions lib/absinthe/blueprint/directive.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,20 @@ defmodule Absinthe.Blueprint.Directive do
@type t :: %__MODULE__{
name: String.t(),
arguments: [Blueprint.Input.Argument.t()],
source_location: nil | Blueprint.Document.SourceLocation.t(),
source_location: nil | Blueprint.SourceLocation.t(),
schema_node: nil | Absinthe.Type.Directive.t(),
flags: Blueprint.flags_t(),
errors: [Phase.Error.t()]
}

@spec expand(t, Blueprint.node_t()) :: {t, map}
def expand(%__MODULE__{schema_node: %{expand: nil}}, node) do
def expand(%__MODULE__{schema_node: nil}, node) do
node
end

def expand(%__MODULE__{schema_node: %{expand: fun}} = directive, node) do
def expand(%__MODULE__{schema_node: type} = directive, node) do
args = Blueprint.Input.Argument.value_map(directive.arguments)
fun.(args, node)
end

def expand(%__MODULE__{schema_node: nil}, node) do
node
Absinthe.Type.function(type, :expand).(args, node)
end

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/document/field.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Absinthe.Blueprint.Document.Field do
directives: [Blueprint.Directive.t()],
flags: Blueprint.flags_t(),
errors: [Phase.Error.t()],
source_location: nil | Blueprint.Document.SourceLocation.t(),
source_location: nil | Blueprint.SourceLocation.t(),
type_conditions: [Blueprint.TypeReference.Name],
schema_node: Type.t(),
complexity: nil | non_neg_integer
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/document/fragment/inline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Absinthe.Blueprint.Document.Fragment.Inline do
flags: Blueprint.flags_t(),
selections: [Blueprint.Document.selection_t()],
schema_node: nil | Absinthe.Type.t(),
source_location: nil | Blueprint.Document.SourceLocation.t(),
source_location: nil | Blueprint.SourceLocation.t(),
type_condition: Blueprint.TypeReference.Name.t()
}
end
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/document/fragment/named.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Absinthe.Blueprint.Document.Fragment.Named do
name: String.t(),
selections: [Blueprint.Document.selection_t()],
schema_node: nil | Absinthe.Type.t(),
source_location: nil | Blueprint.Document.SourceLocation.t(),
source_location: nil | Blueprint.SourceLocation.t(),
flags: Blueprint.flags_t(),
type_condition: Blueprint.TypeReference.Name.t()
}
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/document/fragment/named/use.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ defmodule Absinthe.Blueprint.Document.Fragment.Named.Use do

@type t :: %__MODULE__{
name: String.t(),
source_location: nil | Blueprint.Document.SourceLocation.t()
source_location: nil | Blueprint.SourceLocation.t()
}
end
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/document/fragment/spread.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ defmodule Absinthe.Blueprint.Document.Fragment.Spread do
errors: [Absinthe.Phase.Error.t()],
name: String.t(),
flags: Blueprint.flags_t(),
source_location: nil | Blueprint.Document.SourceLocation.t()
source_location: nil | Blueprint.SourceLocation.t()
}
end
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/document/operation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Absinthe.Blueprint.Document.Operation do
variable_definitions: [Blueprint.Document.VariableDefinition.t()],
variable_uses: [Blueprint.Input.Variable.Use.t()],
fragment_uses: [Blueprint.Document.Fragment.Named.Use.t()],
source_location: nil | Blueprint.Document.SourceLocation.t(),
source_location: nil | Blueprint.SourceLocation.t(),
schema_node: nil | Absinthe.Type.Object.t(),
complexity: nil | non_neg_integer,
provided_values: %{String.t() => nil | Blueprint.Input.t()},
Expand Down
25 changes: 0 additions & 25 deletions lib/absinthe/blueprint/document/source_location.ex

This file was deleted.

2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/document/variable_definition.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Absinthe.Blueprint.Document.VariableDefinition do
name: String.t(),
type: Blueprint.TypeReference.t(),
default_value: Blueprint.Input.t(),
source_location: nil | Blueprint.Document.SourceLocation.t(),
source_location: nil | Blueprint.SourceLocation.t(),
provided_value: nil | Blueprint.Input.t(),
errors: [Absinthe.Phase.Error.t()],
flags: Blueprint.flags_t(),
Expand Down
4 changes: 2 additions & 2 deletions lib/absinthe/blueprint/input/argument.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Absinthe.Blueprint.Input.Argument do
@type t :: %__MODULE__{
name: String.t(),
input_value: Blueprint.Input.Value.t(),
source_location: Blueprint.Document.SourceLocation.t(),
source_location: Blueprint.SourceLocation.t(),
schema_node: nil | Absinthe.Type.Argument.t(),
value: any,
flags: Blueprint.flags_t(),
Expand All @@ -42,6 +42,6 @@ defmodule Absinthe.Blueprint.Input.Argument do
arg ->
arg
end)
|> Map.new(&{&1.schema_node.__reference__.identifier, &1.value})
|> Map.new(&{&1.schema_node.identifier, &1.value})
end
end
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/input/boolean.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Absinthe.Blueprint.Input.Boolean do
value: true | false,
flags: Blueprint.flags_t(),
schema_node: nil | Absinthe.Type.t(),
source_location: Blueprint.Document.SourceLocation.t(),
source_location: Blueprint.SourceLocation.t(),
errors: [Phase.Error.t()]
}
end
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/input/enum.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Absinthe.Blueprint.Input.Enum do
value: String.t(),
flags: Blueprint.flags_t(),
schema_node: nil | Absinthe.Type.t(),
source_location: Blueprint.Document.SourceLocation.t(),
source_location: Blueprint.SourceLocation.t(),
errors: [Phase.Error.t()]
}
end
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/input/field.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Absinthe.Blueprint.Input.Field do
input_value: Blueprint.Input.Value.t(),
flags: Blueprint.flags_t(),
schema_node: nil | Type.Field.t(),
source_location: Blueprint.Document.SourceLocation.t(),
source_location: Blueprint.SourceLocation.t(),
errors: [Absinthe.Phase.Error.t()]
}
end
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/input/float.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Absinthe.Blueprint.Input.Float do
@type t :: %__MODULE__{
value: float,
flags: Blueprint.flags_t(),
source_location: Blueprint.Document.SourceLocation.t(),
source_location: Blueprint.SourceLocation.t(),
schema_node: nil | Absinthe.Type.t(),
errors: [Absinthe.Phase.Error.t()]
}
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/input/integer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Absinthe.Blueprint.Input.Integer do
@type t :: %__MODULE__{
value: integer,
flags: Blueprint.flags_t(),
source_location: Blueprint.Document.SourceLocation.t(),
source_location: Blueprint.SourceLocation.t(),
schema_node: nil | Absinthe.Type.t(),
errors: [Phase.Error.t()]
}
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/input/list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Absinthe.Blueprint.Input.List do
items: [Blueprint.Input.Value.t()],
flags: Blueprint.flags_t(),
schema_node: nil | Absinthe.Type.t(),
source_location: Blueprint.Document.SourceLocation.t(),
source_location: Blueprint.SourceLocation.t(),
errors: [Phase.Error.t()]
}

Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/input/null.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Absinthe.Blueprint.Input.Null do
@type t :: %__MODULE__{
flags: Blueprint.flags_t(),
schema_node: nil | Absinthe.Type.t(),
source_location: Blueprint.Document.SourceLocation.t(),
source_location: Blueprint.SourceLocation.t(),
errors: [Phase.Error.t()]
}
end
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/input/object.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Absinthe.Blueprint.Input.Object do
nil
| Absinthe.Type.InputObject.t()
| Absinthe.Type.NonNull.t(Absinthe.Type.InputObject.t()),
source_location: Blueprint.Document.SourceLocation.t(),
source_location: Blueprint.SourceLocation.t(),
errors: [Absinthe.Phase.Error.t()]
}
end
4 changes: 0 additions & 4 deletions lib/absinthe/blueprint/input/raw_value.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ defmodule Absinthe.Blueprint.Input.RawValue do
defstruct [
:content
]

@type t :: %__MODULE__{
content: Absinthe.Blueprint.Input.t()
}
end
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/input/string.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Absinthe.Blueprint.Input.String do
value: String.t(),
flags: Blueprint.flags_t(),
schema_node: nil | Absinthe.Type.t(),
source_location: Blueprint.Document.SourceLocation.t(),
source_location: Blueprint.SourceLocation.t(),
errors: [Phase.Error.t()]
}
end
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/input/variable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Absinthe.Blueprint.Input.Variable do

@type t :: %__MODULE__{
name: String.t(),
source_location: nil | Blueprint.Document.SourceLocation.t(),
source_location: nil | Blueprint.SourceLocation.t(),
# Added by phases
flags: Blueprint.flags_t(),
errors: [Phase.Error.t()]
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/blueprint/input/variable/use.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ defmodule Absinthe.Blueprint.Input.Variable.Use do

@type t :: %__MODULE__{
name: String.t(),
source_location: nil | Blueprint.Document.SourceLocation.t()
source_location: nil | Blueprint.SourceLocation.t()
}
end
Loading

0 comments on commit 01be95b

Please sign in to comment.