Skip to content

Codec for generating Absinthe JSON schemas in a deterministic format with alphabetically ordered type definitions

License

Notifications You must be signed in to change notification settings

hadfieldn/absinthe_sorting_codec

Repository files navigation

Absinthe Sorting Codec

Build Status Hex pm Hex Docs License

Convert the JSON output of an introspection query into a deterministic ordering of types (sorted by name). This results in saner diffs when committing schemas to version control.

Standalone

Can convert the output of introspection queries in JSON format to a sorted, deterministic ordering of types. See the test fixtures.

Example

AbsintheSortingCodec.encode!(Jason.decode!("swapi.json"))

Absinthe

Can be used to convert an Absinthe schema to a deterministic format by using AbsintheSortingCodec as the JSON encoder.

Example

mix absinthe.schema.json --schema MySchema --json-codec AbsintheSortingCodec --pretty

NOTE: If the mix command gives the following error --

(Argument Error) you atttempted to apply :module on "AbsintheSortingCodec". If you are using apply/3, make sure the module is an atom. If you are using the dot syntax, such as map.field or module.function, make sure the left side of the dot is an atom or a map

-- you need to upgrade to Absinthe 1.4.14 or 1.5 or later.

Installation

If available in Hex, the package can be installed by adding absinthe_sorting_codec to your list of dependencies in mix.exs:

def deps do
  [
    {:absinthe_sorting_codec, "~> 1.0.1"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/absinthe_sorting_codec.

Attribution

Thanks to Maarten van Vliet for developing Absinthe SDL, which this project is patterned after.

About

Codec for generating Absinthe JSON schemas in a deterministic format with alphabetically ordered type definitions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages