├── .prettierignore ├── tests └── gen │ ├── fixtures │ ├── schema-string │ │ ├── query.gql │ │ └── expected-output │ │ │ ├── Query.elm │ │ │ └── GraphQL │ │ │ └── Enum │ │ │ └── TypeKind__.elm │ ├── enums │ │ ├── enum.gql │ │ ├── nullable-enum.gql │ │ ├── schema.gql │ │ └── expected-output │ │ │ ├── NullableEnum.elm │ │ │ ├── Enum.elm │ │ │ └── GraphQL │ │ │ └── Enum │ │ │ ├── Binary.elm │ │ │ ├── UserType.elm │ │ │ └── TypeKind__.elm │ ├── customScalars │ │ ├── custom-scalar-types.gql │ │ ├── custom-nullable-scalar-types.gql │ │ ├── custom-scalar-input.gql │ │ ├── schema.gql │ │ └── expected-output │ │ │ ├── CustomScalarTypes.elm │ │ │ ├── CustomNullableScalarTypes.elm │ │ │ ├── CustomScalarInput.elm │ │ │ └── GraphQL │ │ │ └── Enum │ │ │ └── TypeKind__.elm │ ├── objects │ │ ├── basic.gql │ │ ├── same-type-same-fields.gql │ │ ├── same-type-other-fields.gql │ │ ├── other-type-same-fields.gql │ │ ├── nested.gql │ │ ├── same-type-same-fields-nullable.gql │ │ ├── other-type-other-fields.gql │ │ ├── same-type-same-fields-list.gql │ │ ├── recursive.gql │ │ ├── big.gql │ │ ├── expected-output │ │ │ ├── Basic.elm │ │ │ ├── SameTypeSameFields.elm │ │ │ ├── SameTypeSameFieldsNullable.elm │ │ │ ├── OtherTypeSameFields.elm │ │ │ ├── SameTypeOtherFields.elm │ │ │ ├── SameTypeSameFieldsList.elm │ │ │ ├── Nested.elm │ │ │ ├── GraphQL │ │ │ │ └── Enum │ │ │ │ │ └── TypeKind__.elm │ │ │ ├── OtherTypeOtherFields.elm │ │ │ └── Recursive.elm │ │ └── schema.gql │ ├── operations │ │ ├── anonymous-query.gql │ │ ├── anonymous-mutation.gql │ │ ├── multiple.gql │ │ ├── schema.gql │ │ ├── multiple-fragments.gql │ │ └── expected-output │ │ │ ├── AnonymousQuery.elm │ │ │ ├── AnonymousMutation.elm │ │ │ └── GraphQL │ │ │ └── Enum │ │ │ └── TypeKind__.elm │ ├── variables │ │ ├── inputs.gql │ │ ├── recursive.gql │ │ ├── scalars.gql │ │ ├── inputs-optional.gql │ │ ├── scalars-mixed.gql │ │ ├── scalars-optional.gql │ │ ├── inputs-mixed.gql │ │ ├── inputs-multiple.gql │ │ ├── lists.gql │ │ ├── schema.gql │ │ └── expected-output │ │ │ ├── Scalars.elm │ │ │ ├── ScalarsMixed.elm │ │ │ ├── ScalarsOptional.elm │ │ │ ├── GraphQL │ │ │ └── Enum │ │ │ │ └── TypeKind__.elm │ │ │ ├── Inputs.elm │ │ │ └── InputsMultiple.elm │ ├── scalars │ │ ├── default-scalar-types.gql │ │ ├── default-nullable-scalar-types.gql │ │ ├── schema.gql │ │ └── expected-output │ │ │ ├── DefaultScalarTypes.elm │ │ │ ├── DefaultNullableScalarTypes.elm │ │ │ └── GraphQL │ │ │ └── Enum │ │ │ └── TypeKind__.elm │ ├── inline-fragments │ │ ├── interface-plain.gql │ │ ├── typename-only-more.gql │ │ ├── typename-only.gql │ │ ├── interface-partial.gql │ │ ├── typename-mixed.gql │ │ ├── interface-partial-shared.gql │ │ ├── typename-shared-partial.gql │ │ ├── union.gql │ │ ├── union-list.gql │ │ ├── union-partial.gql │ │ ├── fragment-in-fragment-partial.gql │ │ ├── interface-multiple.gql │ │ ├── single.gql │ │ ├── interface-shared.gql │ │ ├── typename-shared.gql │ │ ├── interface-list-shared.gql │ │ ├── typename.gql │ │ ├── interface.gql │ │ ├── typename-shared-more.gql │ │ ├── interface-list.gql │ │ ├── fragment-in-fragment.gql │ │ ├── fragment-in-fragment-shared.gql │ │ ├── names.gql │ │ ├── schema.gql │ │ └── expected-output │ │ │ ├── InterfacePlain.elm │ │ │ ├── Single.elm │ │ │ ├── Union.elm │ │ │ ├── InterfacePartial.elm │ │ │ ├── UnionList.elm │ │ │ ├── InterfacePartialShared.elm │ │ │ ├── InterfaceMultiple.elm │ │ │ ├── GraphQL │ │ │ └── Enum │ │ │ │ └── TypeKind__.elm │ │ │ ├── UnionPartial.elm │ │ │ ├── FragmentInFragmentPartial.elm │ │ │ └── Interface.elm │ ├── lists │ │ ├── list-of-scalars.gql │ │ ├── list-of-objects.gql │ │ ├── schema.gql │ │ └── expected-output │ │ │ ├── ListOfScalars.elm │ │ │ ├── ListOfObjects.elm │ │ │ └── GraphQL │ │ │ └── Enum │ │ │ └── TypeKind__.elm │ ├── directives │ │ ├── skip.gql │ │ ├── mixed1.gql │ │ ├── mixed2.gql │ │ ├── include.gql │ │ ├── schema.gql │ │ └── expected-output │ │ │ ├── Skip.elm │ │ │ ├── Mixed1.elm │ │ │ ├── Mixed2.elm │ │ │ ├── Include.elm │ │ │ └── GraphQL │ │ │ └── Enum │ │ │ └── TypeKind__.elm │ ├── inline-fragments-throws │ │ ├── same-signature.gql │ │ └── schema.gql │ ├── aliases │ │ ├── schema.gql │ │ ├── query.gql │ │ └── expected-output │ │ │ ├── GraphQL │ │ │ └── Enum │ │ │ │ └── TypeKind__.elm │ │ │ └── Query.elm │ ├── misc │ │ ├── query.gql │ │ ├── schema.gql │ │ └── expected-output │ │ │ └── GraphQL │ │ │ └── Enum │ │ │ └── TypeKind__.elm │ ├── operations-named │ │ ├── schema.gql │ │ ├── query.gql │ │ └── expected-output │ │ │ └── GraphQL │ │ │ └── Enum │ │ │ └── TypeKind__.elm │ ├── operations-named_prefixed │ │ ├── schema.gql │ │ ├── query.gql │ │ ├── Queries │ │ │ └── Query.gql │ │ ├── queries2 │ │ │ └── Queries │ │ │ │ └── query2.gql │ │ └── expected-output │ │ │ └── GraphQL │ │ │ └── Enum │ │ │ └── TypeKind__.elm │ ├── fragments │ │ ├── schema.gql │ │ ├── query.gql │ │ └── expected-output │ │ │ └── GraphQL │ │ │ └── Enum │ │ │ └── TypeKind__.elm │ ├── keywords │ │ ├── query.gql │ │ ├── schema.gql │ │ └── expected-output │ │ │ └── GraphQL │ │ │ └── Enum │ │ │ └── TypeKind__.elm │ └── names │ │ ├── queries.gql │ │ ├── schema.gql │ │ └── expected-output │ │ └── GraphQL │ │ └── Enum │ │ ├── NamesUpper.elm │ │ ├── Names_lower.elm │ │ ├── Names_lowerAndUpper.elm │ │ └── TypeKind__.elm │ ├── test-gen │ ├── start.ts │ └── update.ts │ ├── test-browser │ ├── start.ts │ ├── src │ │ ├── Data │ │ │ ├── Id.elm │ │ │ ├── Binary.elm │ │ │ └── Time.elm │ │ └── GraphQL │ │ │ └── Http.elm │ ├── elm.json │ └── server.ts │ ├── test-options │ └── start.ts │ └── utils │ └── index.ts ├── examples ├── basic │ ├── src │ │ ├── Queries │ │ │ └── Messages.gql │ │ ├── schema.gql │ │ └── GraphQL │ │ │ └── Http.elm │ ├── package.json │ ├── prebuild.js │ ├── elm.json │ ├── server.js │ └── src-generated │ │ ├── Queries │ │ └── Messages.elm │ │ └── GraphQL │ │ └── Enum │ │ └── TypeKind__.elm ├── readme │ ├── src │ │ ├── myQuery.gql │ │ ├── mySchema.gql │ │ └── Main.elm │ ├── package.json │ ├── prebuild.js │ ├── server.js │ ├── elm.json │ └── src-generated │ │ ├── MyQuery.elm │ │ └── GraphQL │ │ └── Enum │ │ └── TypeKind__.elm ├── features │ ├── src │ │ ├── Queries │ │ │ ├── Mutations.gql │ │ │ ├── Variables.gql │ │ │ ├── Aliases.gql │ │ │ ├── Fields.gql │ │ │ └── Fragments.gql │ │ ├── schema.gql │ │ └── GraphQL │ │ │ └── Http.elm │ ├── package.json │ ├── prebuild.js │ ├── server.js │ ├── elm.json │ └── src-generated │ │ ├── Queries │ │ ├── Aliases.elm │ │ ├── Mutations.elm │ │ ├── Fields.elm │ │ ├── Variables.elm │ │ └── Fragments.elm │ │ └── GraphQL │ │ └── Enum │ │ ├── Language.elm │ │ └── TypeKind__.elm └── basic2 │ ├── package.json │ ├── prebuild.js │ ├── src │ ├── Queries │ │ └── Messages.gql │ ├── schema.gql │ └── GraphQL │ │ └── Http.elm │ ├── elm.json │ ├── server.js │ └── src-generated │ └── GraphQL │ └── Enum │ └── TypeKind__.elm ├── .gitignore ├── index.js ├── tsconfig.json ├── index.d.ts ├── elm.json ├── src ├── gen │ └── schema.ts └── GraphQL │ ├── Errors.elm │ ├── Helpers │ └── Decode.elm │ └── Response.elm ├── .github └── workflows │ └── ci.yml └── LICENSE /.prettierignore: -------------------------------------------------------------------------------- 1 | generated* 2 | -------------------------------------------------------------------------------- /tests/gen/fixtures/schema-string/query.gql: -------------------------------------------------------------------------------- 1 | { 2 | hello 3 | } 4 | -------------------------------------------------------------------------------- /tests/gen/fixtures/enums/enum.gql: -------------------------------------------------------------------------------- 1 | { 2 | binary 3 | userType 4 | } 5 | -------------------------------------------------------------------------------- /tests/gen/fixtures/enums/nullable-enum.gql: -------------------------------------------------------------------------------- 1 | { 2 | binaryOrNull 3 | } 4 | -------------------------------------------------------------------------------- /tests/gen/test-gen/start.ts: -------------------------------------------------------------------------------- 1 | import { testGen } from "."; 2 | 3 | testGen(); 4 | -------------------------------------------------------------------------------- /tests/gen/fixtures/customScalars/custom-scalar-types.gql: -------------------------------------------------------------------------------- 1 | { 2 | id 3 | time 4 | } 5 | -------------------------------------------------------------------------------- /examples/basic/src/Queries/Messages.gql: -------------------------------------------------------------------------------- 1 | { 2 | messages { 3 | message 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /examples/readme/src/myQuery.gql: -------------------------------------------------------------------------------- 1 | query UserName { 2 | user { 3 | name 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/basic.gql: -------------------------------------------------------------------------------- 1 | { 2 | i { 3 | name 4 | age 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/gen/test-browser/start.ts: -------------------------------------------------------------------------------- 1 | import { testBrowser } from "."; 2 | 3 | testBrowser(); 4 | -------------------------------------------------------------------------------- /tests/gen/test-options/start.ts: -------------------------------------------------------------------------------- 1 | import { testOptions } from "."; 2 | 3 | testOptions(); 4 | -------------------------------------------------------------------------------- /tests/gen/test-gen/update.ts: -------------------------------------------------------------------------------- 1 | import { testGen } from "."; 2 | 3 | testGen({ update: true }); 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | node_modules 4 | elm-stuff 5 | generated* 6 | index.html 7 | lib 8 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations/anonymous-query.gql: -------------------------------------------------------------------------------- 1 | { 2 | operation { 3 | query 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/gen/fixtures/customScalars/custom-nullable-scalar-types.gql: -------------------------------------------------------------------------------- 1 | { 2 | idOrNull 3 | timeOrNull 4 | } 5 | -------------------------------------------------------------------------------- /tests/gen/fixtures/customScalars/custom-scalar-input.gql: -------------------------------------------------------------------------------- 1 | query At($time: Time!) { 2 | at(time: $time) 3 | } 4 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations/anonymous-mutation.gql: -------------------------------------------------------------------------------- 1 | mutation { 2 | fragment { 3 | name 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/inputs.gql: -------------------------------------------------------------------------------- 1 | query Inputs($inputs: Inputs!) { 2 | inputs(inputs: $inputs) 3 | } 4 | -------------------------------------------------------------------------------- /examples/readme/src/mySchema.gql: -------------------------------------------------------------------------------- 1 | type Query { 2 | user: User! 3 | } 4 | 5 | type User { 6 | name: String! 7 | } 8 | -------------------------------------------------------------------------------- /tests/gen/fixtures/scalars/default-scalar-types.gql: -------------------------------------------------------------------------------- 1 | { 2 | int 3 | float 4 | string 5 | boolean 6 | id 7 | } 8 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/interface-plain.gql: -------------------------------------------------------------------------------- 1 | query InterfacePlain { 2 | animal { 3 | color 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/recursive.gql: -------------------------------------------------------------------------------- 1 | query Recursive($input: RecursiveInput!) { 2 | recursive(input: $input) 3 | } 4 | -------------------------------------------------------------------------------- /examples/features/src/Queries/Mutations.gql: -------------------------------------------------------------------------------- 1 | mutation PostMessage($message: String!) { 2 | postMessage(message: $message) 3 | } 4 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/scalars.gql: -------------------------------------------------------------------------------- 1 | query Scalars($string: String!, $int: Int!) { 2 | scalars(string: $string, int: $int) 3 | } 4 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/inputs-optional.gql: -------------------------------------------------------------------------------- 1 | query InputsOptional($inputs: OptionalInputs) { 2 | inputsOptional(inputs: $inputs) 3 | } 4 | -------------------------------------------------------------------------------- /examples/features/src/Queries/Variables.gql: -------------------------------------------------------------------------------- 1 | query Translation($id: ID!, $language: Language) { 2 | translation(id: $id, language: $language) 3 | } 4 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/typename-only-more.gql: -------------------------------------------------------------------------------- 1 | query TypenameOnlyMore { 2 | animal { 3 | __typename 4 | color 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/scalars-mixed.gql: -------------------------------------------------------------------------------- 1 | query ScalarsMixed($string: String, $int: Int!) { 2 | scalarsMixed(string: $string, int: $int) 3 | } 4 | -------------------------------------------------------------------------------- /examples/features/src/Queries/Aliases.gql: -------------------------------------------------------------------------------- 1 | { 2 | en: translation(id: "hello.world", language: EN) 3 | nl: translation(id: "hello.world", language: NL) 4 | } 5 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/same-type-same-fields.gql: -------------------------------------------------------------------------------- 1 | { 2 | i { 3 | name 4 | age 5 | } 6 | me { 7 | age 8 | name 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/gen/fixtures/scalars/default-nullable-scalar-types.gql: -------------------------------------------------------------------------------- 1 | { 2 | intOrNull 3 | floatOrNull 4 | stringOrNull 5 | booleanOrNull 6 | idOrNull 7 | } 8 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/scalars-optional.gql: -------------------------------------------------------------------------------- 1 | query ScalarsOptional($string: String, $int: Int) { 2 | scalarsOptional(string: $string, int: $int) 3 | } 4 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/typename-only.gql: -------------------------------------------------------------------------------- 1 | query TypenameOnly { 2 | flip { 3 | __typename 4 | } 5 | animal { 6 | __typename 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/gen/fixtures/lists/list-of-scalars.gql: -------------------------------------------------------------------------------- 1 | { 2 | pets_pet 3 | 4 | pets_petOrNull 5 | 6 | petsOrNull_pet 7 | 8 | petsOrNull_petOrNull 9 | } 10 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/same-type-other-fields.gql: -------------------------------------------------------------------------------- 1 | { 2 | i { 3 | name 4 | age 5 | } 6 | me { 7 | email 8 | age 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/other-type-same-fields.gql: -------------------------------------------------------------------------------- 1 | { 2 | me { 3 | name 4 | email 5 | } 6 | you { 7 | name 8 | email 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/interface-partial.gql: -------------------------------------------------------------------------------- 1 | query InterfacePartial { 2 | animal { 3 | ... on Dog { 4 | color 5 | hairy 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/inputs-mixed.gql: -------------------------------------------------------------------------------- 1 | query InputsMixed($inputs: MixedInputs!, $inputs2: MixedInputs) { 2 | inputsMixed(inputs: $inputs, inputs2: $inputs2) 3 | } 4 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/inputs-multiple.gql: -------------------------------------------------------------------------------- 1 | query InputsMultiple($inputs: Inputs!, $inputs2: Inputs) { 2 | inputsMultiple(inputs: $inputs, inputs2: $inputs2) 3 | } 4 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/typename-mixed.gql: -------------------------------------------------------------------------------- 1 | query TypenameMixed { 2 | animal { 3 | __typename 4 | ... on Mammal { 5 | __typename 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/nested.gql: -------------------------------------------------------------------------------- 1 | { 2 | i { 3 | name 4 | age 5 | bestFriend { 6 | name 7 | age 8 | email 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/same-type-same-fields-nullable.gql: -------------------------------------------------------------------------------- 1 | { 2 | you { 3 | email 4 | age 5 | } 6 | youOrNull { 7 | age 8 | email 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/basic/src/schema.gql: -------------------------------------------------------------------------------- 1 | type Query { 2 | messages: [Message!]! 3 | } 4 | 5 | type Message { 6 | message: String! 7 | } 8 | 9 | schema { 10 | query: Query 11 | } 12 | -------------------------------------------------------------------------------- /tests/gen/fixtures/directives/skip.gql: -------------------------------------------------------------------------------- 1 | query Skip($withSchool: Boolean!, $withCity: Boolean!) { 2 | name 3 | school @skip(if: $withSchool) 4 | city @skip(if: $withCity) 5 | } 6 | -------------------------------------------------------------------------------- /tests/gen/fixtures/directives/mixed1.gql: -------------------------------------------------------------------------------- 1 | query Mixed1($withSchool: Boolean!, $withCity: Boolean!) { 2 | name 3 | school @include(if: $withSchool) 4 | city @skip(if: $withCity) 5 | } 6 | -------------------------------------------------------------------------------- /tests/gen/fixtures/directives/mixed2.gql: -------------------------------------------------------------------------------- 1 | query Mixed2($withSchool: Boolean!, $withCity: Boolean!) { 2 | name 3 | school @skip(if: $withSchool) 4 | city @include(if: $withCity) 5 | } 6 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/interface-partial-shared.gql: -------------------------------------------------------------------------------- 1 | query InterfacePartialShared { 2 | animal { 3 | color 4 | ... on Dog { 5 | hairy 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | const lib = require("./lib/graphqlToElm"); 4 | exports.graphqlToElm = lib.graphqlToElm; 5 | exports["default"] = exports.graphqlToElm; 6 | -------------------------------------------------------------------------------- /tests/gen/fixtures/directives/include.gql: -------------------------------------------------------------------------------- 1 | query Include($withSchool: Boolean!, $withCity: Boolean!) { 2 | name 3 | school @include(if: $withSchool) 4 | city @include(if: $withCity) 5 | } 6 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/typename-shared-partial.gql: -------------------------------------------------------------------------------- 1 | query TypenameSharedPartial { 2 | animal { 3 | __typename 4 | ... on Dolphin { 5 | color 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/union.gql: -------------------------------------------------------------------------------- 1 | query Union { 2 | flip { 3 | ... on Heads { 4 | name 5 | } 6 | ... on Tails { 7 | length 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/other-type-other-fields.gql: -------------------------------------------------------------------------------- 1 | { 2 | i { 3 | dog { 4 | name 5 | } 6 | } 7 | me { 8 | name 9 | } 10 | you { 11 | email 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/features/src/Queries/Fields.gql: -------------------------------------------------------------------------------- 1 | { 2 | user { 3 | name 4 | email 5 | } 6 | 7 | lastMessage { 8 | message 9 | } 10 | 11 | messages { 12 | message 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/union-list.gql: -------------------------------------------------------------------------------- 1 | query UnionList { 2 | flips { 3 | ... on Heads { 4 | name 5 | } 6 | ... on Tails { 7 | length 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/gen/fixtures/directives/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | } 6 | 7 | # Query 8 | 9 | type Query { 10 | name: String! 11 | school: String! 12 | city: String 13 | } 14 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/same-type-same-fields-list.gql: -------------------------------------------------------------------------------- 1 | { 2 | me { 3 | bestFriend { 4 | age 5 | name 6 | } 7 | friends { 8 | name 9 | age 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments-throws/same-signature.gql: -------------------------------------------------------------------------------- 1 | query Interface { 2 | animal { 3 | ... on Dog { 4 | color 5 | } 6 | ... on Dolphin { 7 | color 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/union-partial.gql: -------------------------------------------------------------------------------- 1 | query UnionPartial { 2 | flip { 3 | ... on Heads { 4 | name 5 | } 6 | } 7 | flipOrNull { 8 | ... on Tails { 9 | length 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/fragment-in-fragment-partial.gql: -------------------------------------------------------------------------------- 1 | query FragmentInFragmentPartial { 2 | animal { 3 | color 4 | ... on Mammal { 5 | ... on Dog { 6 | hairy 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/interface-multiple.gql: -------------------------------------------------------------------------------- 1 | query InterfaceMultiple { 2 | animal { 3 | ... on Mammal { 4 | subclass 5 | } 6 | ... on Bird { 7 | color 8 | canFly 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/lists.gql: -------------------------------------------------------------------------------- 1 | query Lists( 2 | $ints: [Int!] 3 | $floats: [Float] 4 | $inputs: [Inputs!]! 5 | $inputs2: [OptionalInputs]! 6 | ) { 7 | lists(ints: $ints, floats: $floats, inputs: $inputs, inputs2: $inputs2) 8 | } 9 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/recursive.gql: -------------------------------------------------------------------------------- 1 | { 2 | comments { 3 | message 4 | responses { 5 | message 6 | responses { 7 | message 8 | responses { 9 | message 10 | } 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/gen/test-browser/src/Data/Id.elm: -------------------------------------------------------------------------------- 1 | module Data.Id exposing (Id, decoder) 2 | 3 | import Json.Decode 4 | 5 | 6 | type Id 7 | = Id String 8 | 9 | 10 | decoder : Json.Decode.Decoder Id 11 | decoder = 12 | Json.Decode.map Id Json.Decode.string 13 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/single.gql: -------------------------------------------------------------------------------- 1 | query Single { 2 | single: animal { 3 | ... on Animal { 4 | color 5 | size 6 | } 7 | } 8 | shared: animal { 9 | size 10 | ... on Animal { 11 | color 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/gen/fixtures/aliases/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | } 6 | 7 | # Query 8 | 9 | type Query { 10 | user: User! 11 | userOrNull: User 12 | } 13 | 14 | type User { 15 | id: ID! 16 | name: String! 17 | email: String! 18 | } 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": true, 4 | "noUnusedLocals": true, 5 | "noUnusedParameters": true, 6 | "lib": ["es2017", "esnext.asynciterable"], 7 | "outDir": "lib", 8 | }, 9 | "files": ["src/gen/graphqlToElm.ts"] 10 | } 11 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/interface-shared.gql: -------------------------------------------------------------------------------- 1 | query InterfaceShared { 2 | animal { 3 | color 4 | ... on Dog { 5 | hairy 6 | } 7 | ... on Dolphin { 8 | fins 9 | } 10 | ... on Bird { 11 | canFly 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/typename-shared.gql: -------------------------------------------------------------------------------- 1 | query TypenameShared { 2 | animal { 3 | __typename 4 | ... on Dog { 5 | color 6 | } 7 | ... on Dolphin { 8 | color 9 | } 10 | ... on Bird { 11 | color 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/gen/fixtures/lists/list-of-objects.gql: -------------------------------------------------------------------------------- 1 | { 2 | friends_friend { 3 | name 4 | } 5 | 6 | friends_friendOrNull { 7 | name 8 | } 9 | 10 | friendsOrNull_friend { 11 | name 12 | } 13 | 14 | friendsOrNull_friendOrNull { 15 | name 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/interface-list-shared.gql: -------------------------------------------------------------------------------- 1 | query InterfaceListShared { 2 | animals { 3 | color 4 | ... on Dog { 5 | hairy 6 | } 7 | ... on Dolphin { 8 | fins 9 | } 10 | ... on Bird { 11 | canFly 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations/multiple.gql: -------------------------------------------------------------------------------- 1 | query Query1($name: String) { 2 | operation(name: $name) { 3 | name 4 | } 5 | } 6 | 7 | query Query2 { 8 | operation { 9 | query 10 | } 11 | } 12 | 13 | mutation Mutation { 14 | fragment { 15 | name 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/typename.gql: -------------------------------------------------------------------------------- 1 | query Typename { 2 | animal { 3 | ... on Dog { 4 | __typename 5 | color 6 | } 7 | ... on Dolphin { 8 | __typename 9 | color 10 | } 11 | ... on Bird { 12 | color 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/gen/fixtures/customScalars/schema.gql: -------------------------------------------------------------------------------- 1 | # Scalars 2 | 3 | scalar Time 4 | 5 | # Schema 6 | 7 | schema { 8 | query: Query 9 | } 10 | 11 | # Query 12 | 13 | type Query { 14 | idOrNull: ID 15 | id: ID! 16 | timeOrNull: Time 17 | time: Time! 18 | at(time: Time!): Int 19 | } 20 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/interface.gql: -------------------------------------------------------------------------------- 1 | query Interface { 2 | animal { 3 | ... on Dog { 4 | color 5 | hairy 6 | } 7 | ... on Dolphin { 8 | color 9 | fins 10 | } 11 | ... on Bird { 12 | color 13 | canFly 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/typename-shared-more.gql: -------------------------------------------------------------------------------- 1 | query TypenameSharedMore { 2 | animal { 3 | __typename 4 | size 5 | ... on Dog { 6 | color 7 | } 8 | ... on Dolphin { 9 | color 10 | } 11 | ... on Bird { 12 | color 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/interface-list.gql: -------------------------------------------------------------------------------- 1 | query InterfaceList { 2 | animals { 3 | ... on Dog { 4 | color 5 | hairy 6 | } 7 | ... on Dolphin { 8 | color 9 | fins 10 | } 11 | ... on Bird { 12 | canFly 13 | color 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/fragment-in-fragment.gql: -------------------------------------------------------------------------------- 1 | query FragmentInFragment { 2 | animal { 3 | color 4 | ... on Mammal { 5 | ... on Dog { 6 | hairy 7 | } 8 | ... on Dolphin { 9 | fins 10 | } 11 | } 12 | ... on Bird { 13 | canFly 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/basic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "clean": "npx rimraf src-generated", 5 | "prebuild": "npm run clean && node prebuild", 6 | "build": "npx elm make src/Main.elm --output=index.html", 7 | "serve": "node server", 8 | "start": "npm run build && npm run serve" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/basic2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "clean": "npx rimraf src-generated", 5 | "prebuild": "npm run clean && node prebuild", 6 | "build": "npx elm make src/Main.elm --output=index.html", 7 | "serve": "node server", 8 | "start": "npm run build && npm run serve" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/readme/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "clean": "npx rimraf src-generated", 5 | "prebuild": "npm run clean && node prebuild", 6 | "build": "npx elm make src/Main.elm --output=index.html", 7 | "serve": "node server", 8 | "start": "npm run build && npm run serve" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/readme/prebuild.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | const { graphqlToElm } = require("../.."); 4 | 5 | graphqlToElm({ 6 | schema: "./src/mySchema.gql", 7 | queries: ["./src/myQuery.gql"], 8 | src: "./src", 9 | dest: "./src-generated", 10 | }).catch((error) => { 11 | console.error(error); 12 | process.exit(1); 13 | }); 14 | -------------------------------------------------------------------------------- /examples/basic/prebuild.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | const { graphqlToElm } = require("../.."); 4 | 5 | graphqlToElm({ 6 | schema: "./src/schema.gql", 7 | queries: ["./src/Queries/Messages.gql"], 8 | src: "./src", 9 | dest: "./src-generated", 10 | }).catch((error) => { 11 | console.error(error); 12 | process.exit(1); 13 | }); 14 | -------------------------------------------------------------------------------- /examples/basic2/prebuild.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | const { graphqlToElm } = require("../.."); 4 | 5 | graphqlToElm({ 6 | schema: "./src/schema.gql", 7 | queries: ["./src/Queries/Messages.gql"], 8 | src: "./src", 9 | dest: "./src-generated", 10 | }).catch((error) => { 11 | console.error(error); 12 | process.exit(1); 13 | }); 14 | -------------------------------------------------------------------------------- /examples/features/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "clean": "npx rimraf src-generated", 5 | "prebuild": "npm run clean && node prebuild", 6 | "build": "npx elm make src/Main.elm --output=index.html", 7 | "serve": "node server", 8 | "start": "npm run build && npm run serve" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/basic2/src/Queries/Messages.gql: -------------------------------------------------------------------------------- 1 | query Messages { 2 | messages { 3 | id 4 | message 5 | } 6 | } 7 | 8 | mutation PostMessage($message: String!) { 9 | postMessage(message: $message) { 10 | ... on Message { 11 | id 12 | message 13 | } 14 | ... on MutationError { 15 | error 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/gen/fixtures/enums/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | } 6 | 7 | # Query 8 | 9 | type Query { 10 | binaryOrNull: Binary 11 | binary: Binary! 12 | userType: USER_TYPE! 13 | } 14 | 15 | enum Binary { 16 | ZERO 17 | ONE 18 | } 19 | 20 | enum USER_TYPE { 21 | REGULAR_USER 22 | ADMIN_USER 23 | TEMP__ADMIN_USER 24 | } 25 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/fragment-in-fragment-shared.gql: -------------------------------------------------------------------------------- 1 | query FragmentInFragmentShared { 2 | animal { 3 | color 4 | ... on Mammal { 5 | subclass 6 | ... on Dog { 7 | hairy 8 | } 9 | ... on Dolphin { 10 | fins 11 | } 12 | } 13 | ... on Bird { 14 | canFly 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/gen/fixtures/scalars/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | } 6 | 7 | # Query 8 | 9 | type Query { 10 | intOrNull: Int 11 | int: Int! 12 | floatOrNull: Float 13 | float: Float! 14 | stringOrNull: String 15 | string: String! 16 | booleanOrNull: Boolean 17 | boolean: Boolean! 18 | idOrNull: ID 19 | id: ID! 20 | } 21 | -------------------------------------------------------------------------------- /examples/features/prebuild.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | const glob = require("glob"); 4 | const { graphqlToElm } = require("../.."); 5 | 6 | graphqlToElm({ 7 | schema: "./src/schema.gql", 8 | queries: glob.sync("./src/Queries/*.gql"), 9 | src: "./src", 10 | dest: "./src-generated", 11 | }).catch((error) => { 12 | console.error(error); 13 | process.exit(1); 14 | }); 15 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments-throws/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | } 6 | 7 | # Query 8 | 9 | type Query { 10 | animal: Animal! 11 | } 12 | 13 | interface Animal { 14 | color: String! 15 | } 16 | 17 | type Dog implements Animal { 18 | color: String! 19 | } 20 | 21 | type Dolphin implements Animal { 22 | color: String! 23 | } 24 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | export as namespace graphqlToElm; 2 | import { Options } from "./src/gen/options"; 3 | export { 4 | Options, 5 | SchemaString, 6 | EnumOptions, 7 | TypeEncoders, 8 | TypeEncoder, 9 | TypeDecoders, 10 | TypeDecoder, 11 | } from "./src/gen/options"; 12 | export declare const graphqlToElm: (options: Options) => Promise; 13 | export default graphqlToElm; 14 | -------------------------------------------------------------------------------- /tests/gen/fixtures/misc/query.gql: -------------------------------------------------------------------------------- 1 | query TestQuery { 2 | i { 3 | name 4 | } 5 | version 6 | me { 7 | name 8 | age 9 | } 10 | you { 11 | name 12 | friends { 13 | id 14 | age 15 | } 16 | relatives { 17 | name 18 | } 19 | } 20 | them { 21 | age 22 | name 23 | } 24 | maybeThem { 25 | age 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/gen/fixtures/aliases/query.gql: -------------------------------------------------------------------------------- 1 | query Aliases { 2 | user1: user { 3 | id 4 | email 5 | } 6 | user2: user { 7 | id 8 | name 9 | } 10 | user3: user { 11 | id 12 | email 13 | } 14 | user4: userOrNull { 15 | id 16 | name 17 | } 18 | user { 19 | id 20 | email 21 | } 22 | userOrNull { 23 | id 24 | name 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/features/src/Queries/Fragments.gql: -------------------------------------------------------------------------------- 1 | query { 2 | user { 3 | ...userFields 4 | } 5 | 6 | lastMessage { 7 | ...messageFields 8 | } 9 | 10 | messages { 11 | ...messageFields 12 | } 13 | } 14 | 15 | fragment userFields on User { 16 | id 17 | name 18 | email 19 | } 20 | 21 | fragment messageFields on Message { 22 | id 23 | from { 24 | ...userFields 25 | } 26 | message 27 | } 28 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations-named/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | mutation: Mutation 6 | } 7 | 8 | # Query 9 | 10 | type Query { 11 | operation(name: String): Operation 12 | } 13 | 14 | type Operation { 15 | name: String 16 | query: String! 17 | fragmentNames: [String!] 18 | } 19 | 20 | type Mutation { 21 | fragment: Fragment 22 | } 23 | 24 | type Fragment { 25 | name: String! 26 | } 27 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations-named_prefixed/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | mutation: Mutation 6 | } 7 | 8 | # Query 9 | 10 | type Query { 11 | operation(name: String): Operation 12 | } 13 | 14 | type Operation { 15 | name: String 16 | query: String! 17 | fragmentNames: [String!] 18 | } 19 | 20 | type Mutation { 21 | fragment: Fragment 22 | } 23 | 24 | type Fragment { 25 | name: String! 26 | } 27 | -------------------------------------------------------------------------------- /tests/gen/fixtures/lists/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | } 6 | 7 | # Query 8 | 9 | type Query { 10 | friends_friend: [Friend!]! 11 | friends_friendOrNull: [Friend]! 12 | friendsOrNull_friend: [Friend!] 13 | friendsOrNull_friendOrNull: [Friend] 14 | 15 | pets_pet: [String!]! 16 | pets_petOrNull: [String]! 17 | petsOrNull_pet: [String!] 18 | petsOrNull_petOrNull: [String] 19 | } 20 | 21 | type Friend { 22 | name: String 23 | } 24 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | mutation: Mutation 6 | } 7 | 8 | # Query 9 | 10 | type Query { 11 | operation(name: String): Operation 12 | current: Operation! 13 | fragment: Fragment! 14 | } 15 | 16 | type Operation { 17 | name: String 18 | query: String! 19 | fragmentNames: [String!] 20 | } 21 | 22 | type Mutation { 23 | fragment: Fragment 24 | } 25 | 26 | type Fragment { 27 | name: String! 28 | } 29 | -------------------------------------------------------------------------------- /examples/basic2/src/schema.gql: -------------------------------------------------------------------------------- 1 | # Query 2 | 3 | type Query { 4 | messages: [Message!]! 5 | } 6 | 7 | type Message { 8 | id: Int! 9 | message: String! 10 | } 11 | 12 | # Mutation 13 | 14 | type Mutation { 15 | postMessage(message: String!): PostMessageResponse! 16 | } 17 | 18 | union PostMessageResponse = Message | MutationError 19 | 20 | type MutationError { 21 | error: String! 22 | } 23 | 24 | # Schema 25 | 26 | schema { 27 | query: Query 28 | mutation: Mutation 29 | } 30 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/names.gql: -------------------------------------------------------------------------------- 1 | query Names { 2 | flip1: flip { 3 | ... on Heads { 4 | name 5 | } 6 | ... on Tails { 7 | length 8 | } 9 | } 10 | 11 | flip2: flip { 12 | ... on Heads { 13 | name 14 | } 15 | ... on Tails { 16 | length 17 | } 18 | } 19 | 20 | flip3: flip { 21 | ... on Heads { 22 | name 23 | } 24 | } 25 | 26 | flip4: flip { 27 | ... on Tails { 28 | length 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations-named/query.gql: -------------------------------------------------------------------------------- 1 | query Query1($name: String) { 2 | operation(name: $name) { 3 | ...fields1 4 | } 5 | } 6 | 7 | query Query2 { 8 | operation { 9 | ...fields2 10 | } 11 | } 12 | 13 | mutation Mutation { 14 | fragment { 15 | ...fields3 16 | } 17 | } 18 | 19 | fragment fields1 on Operation { 20 | name 21 | fragmentNames 22 | } 23 | 24 | fragment fields2 on Operation { 25 | query 26 | } 27 | 28 | fragment fields3 on Fragment { 29 | name 30 | } 31 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations-named_prefixed/query.gql: -------------------------------------------------------------------------------- 1 | query Query1($name: String) { 2 | operation(name: $name) { 3 | ...fields1 4 | } 5 | } 6 | 7 | query Query2 { 8 | operation { 9 | ...fields2 10 | } 11 | } 12 | 13 | mutation Mutation { 14 | fragment { 15 | ...fields3 16 | } 17 | } 18 | 19 | fragment fields1 on Operation { 20 | name 21 | fragmentNames 22 | } 23 | 24 | fragment fields2 on Operation { 25 | query 26 | } 27 | 28 | fragment fields3 on Fragment { 29 | name 30 | } 31 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations-named_prefixed/Queries/Query.gql: -------------------------------------------------------------------------------- 1 | query Query1($name: String) { 2 | operation(name: $name) { 3 | ...fields1 4 | } 5 | } 6 | 7 | query Query2 { 8 | operation { 9 | ...fields2 10 | } 11 | } 12 | 13 | mutation Mutation { 14 | fragment { 15 | ...fields3 16 | } 17 | } 18 | 19 | fragment fields1 on Operation { 20 | name 21 | fragmentNames 22 | } 23 | 24 | fragment fields2 on Operation { 25 | query 26 | } 27 | 28 | fragment fields3 on Fragment { 29 | name 30 | } 31 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations-named_prefixed/queries2/Queries/query2.gql: -------------------------------------------------------------------------------- 1 | query Query1($name: String) { 2 | operation(name: $name) { 3 | ...fields1 4 | } 5 | } 6 | 7 | query Query2 { 8 | operation { 9 | ...fields2 10 | } 11 | } 12 | 13 | mutation Mutation { 14 | fragment { 15 | ...fields3 16 | } 17 | } 18 | 19 | fragment fields1 on Operation { 20 | name 21 | fragmentNames 22 | } 23 | 24 | fragment fields2 on Operation { 25 | query 26 | } 27 | 28 | fragment fields3 on Fragment { 29 | name 30 | } 31 | -------------------------------------------------------------------------------- /tests/gen/fixtures/fragments/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | } 6 | 7 | # Query 8 | 9 | type Query { 10 | user: User! 11 | userOrNull: User 12 | userById(id: String!): User 13 | flip: Flip! 14 | } 15 | 16 | type User { 17 | id: ID! 18 | name: String! 19 | email: String! 20 | profile: Profile 21 | } 22 | 23 | type Profile { 24 | id: ID! 25 | name: String! 26 | image: String 27 | } 28 | 29 | union Flip = Heads | Tails 30 | 31 | type Heads { 32 | name: String! 33 | } 34 | 35 | type Tails { 36 | length: Float! 37 | } 38 | -------------------------------------------------------------------------------- /tests/gen/fixtures/misc/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | mutation: Mutation 6 | } 7 | 8 | # Query 9 | 10 | type Query { 11 | version: Int! 12 | i: User! 13 | me: User! 14 | you: User 15 | them: [User!]! 16 | maybeThem: [User] 17 | } 18 | 19 | type User { 20 | id: ID! 21 | name: String! 22 | age: Int 23 | friends: [User!] 24 | relatives: [User!]! 25 | others: [User] 26 | } 27 | 28 | # Mutation 29 | 30 | type Mutation { 31 | test(value: String): Response 32 | } 33 | 34 | type Response { 35 | status: Int 36 | } 37 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations/multiple-fragments.gql: -------------------------------------------------------------------------------- 1 | query Query1($name: String) { 2 | operation(name: $name) { 3 | ...fields1 4 | } 5 | } 6 | 7 | query Query2 { 8 | operation { 9 | ...fields2 10 | } 11 | current { 12 | ...fields2 13 | } 14 | fragment { 15 | ...fields3 16 | } 17 | } 18 | 19 | mutation Mutation { 20 | fragment { 21 | ...fields3 22 | } 23 | } 24 | 25 | fragment fields1 on Operation { 26 | name 27 | fragmentNames 28 | } 29 | 30 | fragment fields2 on Operation { 31 | query 32 | } 33 | 34 | fragment fields3 on Fragment { 35 | name 36 | } 37 | -------------------------------------------------------------------------------- /examples/basic/src/GraphQL/Http.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Http exposing (get) 2 | 3 | import GraphQL.Errors exposing (Errors) 4 | import GraphQL.Operation exposing (Operation, Query) 5 | import GraphQL.Response exposing (Response) 6 | import Http 7 | import Url.Builder 8 | 9 | 10 | get : Operation Query Errors a -> (Result Http.Error (Response Errors a) -> msg) -> Cmd msg 11 | get operation msg = 12 | Http.get 13 | { url = Url.Builder.absolute [ "graphql" ] (GraphQL.Operation.queryParameters operation) 14 | , expect = Http.expectJson msg (GraphQL.Response.decoder operation) 15 | } 16 | -------------------------------------------------------------------------------- /examples/features/server.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | const { readFileSync } = require("fs"); 4 | const express = require("express"); 5 | const { ApolloServer, gql } = require("apollo-server-express"); 6 | 7 | const typeDefs = gql(readFileSync("src/schema.gql", "utf8")); 8 | const server = new ApolloServer({ typeDefs, mocks: true }); 9 | const app = express(); 10 | server.start().then(() => { 11 | server.applyMiddleware({ app }); 12 | app.use(express.static(__dirname)); 13 | app.listen(3000); 14 | 15 | console.log("example : http://localhost:3000"); 16 | console.log("playground : http://localhost:3000/graphql"); 17 | }); 18 | -------------------------------------------------------------------------------- /examples/features/src/schema.gql: -------------------------------------------------------------------------------- 1 | # Enums 2 | 3 | enum Language { 4 | EN 5 | NL 6 | } 7 | 8 | # Schema 9 | 10 | schema { 11 | query: Query 12 | mutation: Mutation 13 | } 14 | 15 | # Query 16 | 17 | type Query { 18 | user: User! 19 | messages: [Message!]! 20 | lastMessage: Message 21 | translation(id: ID!, language: Language): String 22 | } 23 | 24 | type User { 25 | id: ID! 26 | name: String! 27 | email: String! 28 | } 29 | 30 | type Message { 31 | id: ID! 32 | from: User! 33 | message: String! 34 | } 35 | 36 | # Mutation 37 | 38 | type Mutation { 39 | postMessage(message: String!): ID 40 | } 41 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/big.gql: -------------------------------------------------------------------------------- 1 | { 2 | i { 3 | intel { 4 | field1 5 | field2 6 | field3 7 | field4 8 | field5 9 | field6 10 | field7 11 | field8 12 | field9 13 | field10 14 | field11 15 | field12 16 | } 17 | intel10 { 18 | field1 19 | field2 20 | field3 21 | field4 22 | field5 23 | field6 24 | field7 25 | field8 26 | field9 27 | field10 28 | __typename 29 | ... on Intel { 30 | field11 31 | field12 32 | } 33 | ... on OtherIntel { 34 | field11 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/readme/server.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | const { readFileSync } = require("fs"); 4 | const express = require("express"); 5 | const { ApolloServer, gql } = require("apollo-server-express"); 6 | 7 | const typeDefs = gql(readFileSync("src/mySchema.gql", "utf8")); 8 | 9 | const resolvers = { 10 | Query: { 11 | user: () => ({ name: "Mario" }), 12 | }, 13 | }; 14 | 15 | const server = new ApolloServer({ 16 | typeDefs, 17 | resolvers, 18 | }); 19 | 20 | const app = express(); 21 | server.start().then(() => { 22 | server.applyMiddleware({ app }); 23 | app.use(express.static(__dirname)); 24 | app.listen(3000); 25 | 26 | console.log("example : http://localhost:3000"); 27 | console.log("playground : http://localhost:3000/graphql"); 28 | }); 29 | -------------------------------------------------------------------------------- /tests/gen/test-browser/src/Data/Binary.elm: -------------------------------------------------------------------------------- 1 | module Data.Binary exposing (Binary, decoder) 2 | 3 | import Json.Decode 4 | 5 | 6 | type Binary 7 | = Zero 8 | | One 9 | 10 | 11 | decoder : Json.Decode.Decoder Binary 12 | decoder = 13 | Json.Decode.string 14 | |> Json.Decode.andThen 15 | (\string -> 16 | case string of 17 | "ZERO" -> 18 | Json.Decode.succeed Zero 19 | 20 | "ONE" -> 21 | Json.Decode.succeed One 22 | 23 | _ -> 24 | Json.Decode.fail <| 25 | "Can not convert '" 26 | ++ string 27 | ++ "' to Binary type" 28 | ) 29 | -------------------------------------------------------------------------------- /examples/basic/elm.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "application", 3 | "source-directories": [ 4 | "src", 5 | "src-generated", 6 | "../../src" 7 | ], 8 | "elm-version": "0.19.1", 9 | "dependencies": { 10 | "direct": { 11 | "elm/browser": "1.0.2", 12 | "elm/core": "1.0.5", 13 | "elm/html": "1.0.0", 14 | "elm/http": "2.0.0", 15 | "elm/json": "1.1.3", 16 | "elm/url": "1.0.0" 17 | }, 18 | "indirect": { 19 | "elm/bytes": "1.0.8", 20 | "elm/file": "1.0.5", 21 | "elm/time": "1.0.0", 22 | "elm/virtual-dom": "1.0.3" 23 | } 24 | }, 25 | "test-dependencies": { 26 | "direct": {}, 27 | "indirect": {} 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/basic2/elm.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "application", 3 | "source-directories": [ 4 | "src", 5 | "src-generated", 6 | "../../src" 7 | ], 8 | "elm-version": "0.19.1", 9 | "dependencies": { 10 | "direct": { 11 | "elm/browser": "1.0.2", 12 | "elm/core": "1.0.5", 13 | "elm/html": "1.0.0", 14 | "elm/http": "2.0.0", 15 | "elm/json": "1.1.3", 16 | "elm/url": "1.0.0" 17 | }, 18 | "indirect": { 19 | "elm/bytes": "1.0.8", 20 | "elm/file": "1.0.5", 21 | "elm/time": "1.0.0", 22 | "elm/virtual-dom": "1.0.3" 23 | } 24 | }, 25 | "test-dependencies": { 26 | "direct": {}, 27 | "indirect": {} 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/readme/elm.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "application", 3 | "source-directories": [ 4 | "src", 5 | "src-generated", 6 | "../../src" 7 | ], 8 | "elm-version": "0.19.1", 9 | "dependencies": { 10 | "direct": { 11 | "elm/browser": "1.0.2", 12 | "elm/core": "1.0.5", 13 | "elm/html": "1.0.0", 14 | "elm/http": "2.0.0", 15 | "elm/json": "1.1.3", 16 | "elm/url": "1.0.0" 17 | }, 18 | "indirect": { 19 | "elm/bytes": "1.0.8", 20 | "elm/file": "1.0.5", 21 | "elm/time": "1.0.0", 22 | "elm/virtual-dom": "1.0.3" 23 | } 24 | }, 25 | "test-dependencies": { 26 | "direct": {}, 27 | "indirect": {} 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/features/elm.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "application", 3 | "source-directories": [ 4 | "src", 5 | "src-generated", 6 | "../../src" 7 | ], 8 | "elm-version": "0.19.1", 9 | "dependencies": { 10 | "direct": { 11 | "elm/browser": "1.0.2", 12 | "elm/core": "1.0.5", 13 | "elm/html": "1.0.0", 14 | "elm/http": "2.0.0", 15 | "elm/json": "1.1.3", 16 | "elm/url": "1.0.0" 17 | }, 18 | "indirect": { 19 | "elm/bytes": "1.0.8", 20 | "elm/file": "1.0.5", 21 | "elm/time": "1.0.0", 22 | "elm/virtual-dom": "1.0.3" 23 | } 24 | }, 25 | "test-dependencies": { 26 | "direct": {}, 27 | "indirect": {} 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /elm.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "package", 3 | "name": "harmboschloo/graphql-to-elm", 4 | "summary": "Generate Elm types/encoders/decoders from GraphQL queries", 5 | "license": "BSD-3-Clause", 6 | "version": "1.0.0", 7 | "exposed-modules": [ 8 | "GraphQL.Helpers.Decode", 9 | "GraphQL.Batch", 10 | "GraphQL.Errors", 11 | "GraphQL.Operation", 12 | "GraphQL.Optional", 13 | "GraphQL.PlainBatch", 14 | "GraphQL.Response" 15 | ], 16 | "elm-version": "0.19.0 <= v < 0.20.0", 17 | "dependencies": { 18 | "elm/core": "1.0.0 <= v < 2.0.0", 19 | "elm/json": "1.0.0 <= v < 2.0.0", 20 | "elm/url": "1.0.0 <= v < 2.0.0" 21 | }, 22 | "test-dependencies": { 23 | "elm-explorations/test": "2.0.0 <= v < 3.0.0" 24 | } 25 | } -------------------------------------------------------------------------------- /tests/gen/test-browser/elm.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "application", 3 | "source-directories": [ 4 | "src", 5 | "generated", 6 | "../../../src" 7 | ], 8 | "elm-version": "0.19.1", 9 | "dependencies": { 10 | "direct": { 11 | "elm/browser": "1.0.2", 12 | "elm/core": "1.0.5", 13 | "elm/html": "1.0.0", 14 | "elm/http": "2.0.0", 15 | "elm/json": "1.1.3", 16 | "elm/time": "1.0.0", 17 | "elm/url": "1.0.0" 18 | }, 19 | "indirect": { 20 | "elm/bytes": "1.0.8", 21 | "elm/file": "1.0.5", 22 | "elm/virtual-dom": "1.0.3" 23 | } 24 | }, 25 | "test-dependencies": { 26 | "direct": {}, 27 | "indirect": {} 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/gen/schema.ts: -------------------------------------------------------------------------------- 1 | import { GraphQLSchema, buildSchema } from "graphql"; 2 | import { SchemaString } from "./options"; 3 | import { readFile } from "./utils"; 4 | 5 | export const getSchemaString = ({ 6 | schema, 7 | log, 8 | }: { 9 | schema: string | SchemaString; 10 | log?: (message: string) => void; 11 | }): Promise => { 12 | if (typeof schema === "string") { 13 | log && log(`reading schema ${schema}`); 14 | return readFile(schema); 15 | } else { 16 | log && log("schema from string"); 17 | return Promise.resolve(schema.string); 18 | } 19 | }; 20 | 21 | export const processSchemaString = (schemaString: string): GraphQLSchema => { 22 | try { 23 | return buildSchema(schemaString); 24 | } catch (error) { 25 | throw new Error(`processing schema\n${error}`); 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /examples/basic/server.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | const { readFileSync } = require("fs"); 4 | const express = require("express"); 5 | const { ApolloServer, gql } = require("apollo-server-express"); 6 | 7 | const messages = [{ message: "Hello" }, { message: "World" }]; 8 | 9 | const typeDefs = gql(readFileSync("src/schema.gql", "utf8")); 10 | 11 | const resolvers = { 12 | Query: { 13 | messages: () => messages, 14 | }, 15 | }; 16 | 17 | const server = new ApolloServer({ 18 | typeDefs, 19 | resolvers, 20 | }); 21 | 22 | const app = express(); 23 | 24 | server.start().then(() => { 25 | server.applyMiddleware({ app }); 26 | app.use(express.static(__dirname)); 27 | app.listen(3000); 28 | 29 | console.log("example : http://localhost:3000"); 30 | console.log("playground : http://localhost:3000/graphql"); 31 | }); 32 | -------------------------------------------------------------------------------- /tests/gen/test-browser/src/Data/Time.elm: -------------------------------------------------------------------------------- 1 | module Data.Time exposing (Posix, decoder, encode) 2 | 3 | import Json.Decode 4 | import Json.Encode 5 | import Time 6 | 7 | 8 | type alias Posix = 9 | Time.Posix 10 | 11 | 12 | encode : Posix -> Json.Encode.Value 13 | encode = 14 | Time.posixToMillis >> String.fromInt >> Json.Encode.string 15 | 16 | 17 | decoder : Json.Decode.Decoder Posix 18 | decoder = 19 | Json.Decode.string 20 | |> Json.Decode.andThen 21 | (\millisString -> 22 | case String.toInt millisString of 23 | Nothing -> 24 | Json.Decode.fail 25 | ("expect integer but got '" ++ millisString ++ "'") 26 | 27 | Just millis -> 28 | Json.Decode.succeed (Time.millisToPosix millis) 29 | ) 30 | -------------------------------------------------------------------------------- /tests/gen/fixtures/schema-string/expected-output/Query.elm: -------------------------------------------------------------------------------- 1 | module Query exposing 2 | ( Query 3 | , Response 4 | , query 5 | ) 6 | 7 | import GraphQL.Errors 8 | import GraphQL.Operation 9 | import GraphQL.Response 10 | import Json.Decode 11 | 12 | 13 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 14 | query = 15 | GraphQL.Operation.withQuery 16 | """{ 17 | hello 18 | }""" 19 | Maybe.Nothing 20 | queryDecoder 21 | GraphQL.Errors.decoder 22 | 23 | 24 | type alias Response = 25 | GraphQL.Response.Response GraphQL.Errors.Errors Query 26 | 27 | 28 | type alias Query = 29 | { hello : String 30 | } 31 | 32 | 33 | queryDecoder : Json.Decode.Decoder Query 34 | queryDecoder = 35 | Json.Decode.map Query 36 | (Json.Decode.field "hello" Json.Decode.string) 37 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | } 6 | 7 | # Query 8 | 9 | type Query { 10 | flip: Flip! 11 | flipOrNull: Flip 12 | flips: [Flip!]! 13 | animal: Animal! 14 | animals: [Animal!]! 15 | } 16 | 17 | union Flip = Heads | Tails 18 | 19 | type Heads { 20 | name: String! 21 | } 22 | 23 | type Tails { 24 | length: Float! 25 | } 26 | 27 | interface Animal { 28 | color: String! 29 | size: Float! 30 | } 31 | 32 | interface Mammal { 33 | color: String! 34 | subclass: String! 35 | } 36 | 37 | type Dog implements Animal & Mammal { 38 | color: String! 39 | size: Float! 40 | hairy: Boolean! 41 | subclass: String! 42 | } 43 | 44 | type Dolphin implements Animal & Mammal { 45 | color: String! 46 | size: Float! 47 | fins: Int! 48 | subclass: String! 49 | } 50 | 51 | type Bird implements Animal { 52 | color: String! 53 | size: Float! 54 | canFly: Boolean! 55 | } 56 | -------------------------------------------------------------------------------- /tests/gen/fixtures/enums/expected-output/NullableEnum.elm: -------------------------------------------------------------------------------- 1 | module NullableEnum exposing 2 | ( Query 3 | , Response 4 | , query 5 | ) 6 | 7 | import Data.Binary 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | 13 | 14 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 15 | query = 16 | GraphQL.Operation.withQuery 17 | """{ 18 | binaryOrNull 19 | }""" 20 | Maybe.Nothing 21 | queryDecoder 22 | GraphQL.Errors.decoder 23 | 24 | 25 | type alias Response = 26 | GraphQL.Response.Response GraphQL.Errors.Errors Query 27 | 28 | 29 | type alias Query = 30 | { binaryOrNull : Maybe.Maybe Data.Binary.Binary 31 | } 32 | 33 | 34 | queryDecoder : Json.Decode.Decoder Query 35 | queryDecoder = 36 | Json.Decode.map Query 37 | (Json.Decode.field "binaryOrNull" (Json.Decode.nullable Data.Binary.decoder)) 38 | -------------------------------------------------------------------------------- /tests/gen/fixtures/keywords/query.gql: -------------------------------------------------------------------------------- 1 | { 2 | elmKeywords { 3 | as 4 | case 5 | else 6 | exposing 7 | if 8 | import 9 | in 10 | let 11 | # module 12 | # of 13 | # port 14 | # then 15 | # type 16 | # where 17 | } 18 | 19 | otherElmKeywords { 20 | alias 21 | command 22 | effect 23 | false 24 | infix 25 | left 26 | non 27 | null 28 | # right 29 | # subscription 30 | # true 31 | } 32 | 33 | elmBasics { 34 | not 35 | flip 36 | String 37 | Int 38 | infix 39 | min 40 | Just 41 | True 42 | } 43 | 44 | boolean { 45 | is 46 | } 47 | 48 | list { 49 | is 50 | } 51 | 52 | graphqlToElmReservedWords { 53 | Variables 54 | Data 55 | query 56 | encodeVariables 57 | decoder 58 | } 59 | 60 | misc { 61 | else 62 | else_ 63 | type_ 64 | Variables2 65 | decoder2 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/gen/fixtures/customScalars/expected-output/CustomScalarTypes.elm: -------------------------------------------------------------------------------- 1 | module CustomScalarTypes exposing 2 | ( Query 3 | , Response 4 | , query 5 | ) 6 | 7 | import Data.Id 8 | import Data.Time 9 | import GraphQL.Errors 10 | import GraphQL.Operation 11 | import GraphQL.Response 12 | import Json.Decode 13 | 14 | 15 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 16 | query = 17 | GraphQL.Operation.withQuery 18 | """{ 19 | id 20 | time 21 | }""" 22 | Maybe.Nothing 23 | queryDecoder 24 | GraphQL.Errors.decoder 25 | 26 | 27 | type alias Response = 28 | GraphQL.Response.Response GraphQL.Errors.Errors Query 29 | 30 | 31 | type alias Query = 32 | { id : Data.Id.Id 33 | , time : Data.Time.Posix 34 | } 35 | 36 | 37 | queryDecoder : Json.Decode.Decoder Query 38 | queryDecoder = 39 | Json.Decode.map2 Query 40 | (Json.Decode.field "id" Data.Id.decoder) 41 | (Json.Decode.field "time" Data.Time.decoder) 42 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Build and Test 2 | on: [push, pull_request] 3 | 4 | jobs: 5 | ci: 6 | runs-on: ${{ matrix.os }} 7 | 8 | strategy: 9 | matrix: 10 | os: 11 | - ubuntu-latest 12 | - macos-latest 13 | # - windows-latest # needs git config core.autocrlf input 14 | 15 | node_version: 16 | - 16 17 | - 18 18 | 19 | name: Node ${{ matrix.node_version }} - ${{ matrix.os }} 20 | 21 | steps: 22 | - name: Checkout 23 | uses: actions/checkout@v3 24 | 25 | - name: Setup Node.js 26 | uses: actions/setup-node@v3 27 | with: 28 | node-version: ${{ matrix.node_version }} 29 | 30 | - name: Install dependencies 31 | run: npm ci 32 | 33 | - name: Validate code 34 | run: npm run validate 35 | 36 | - name: Build library 37 | run: npm run build 38 | 39 | - name: Build examples 40 | run: npm run examples-build 41 | 42 | - name: Run tests 43 | run: npm run test 44 | -------------------------------------------------------------------------------- /tests/gen/fixtures/enums/expected-output/Enum.elm: -------------------------------------------------------------------------------- 1 | module Enum exposing 2 | ( Query 3 | , Response 4 | , query 5 | ) 6 | 7 | import Data.Binary 8 | import GraphQL.Enum.UserType 9 | import GraphQL.Errors 10 | import GraphQL.Operation 11 | import GraphQL.Response 12 | import Json.Decode 13 | 14 | 15 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 16 | query = 17 | GraphQL.Operation.withQuery 18 | """{ 19 | binary 20 | userType 21 | }""" 22 | Maybe.Nothing 23 | queryDecoder 24 | GraphQL.Errors.decoder 25 | 26 | 27 | type alias Response = 28 | GraphQL.Response.Response GraphQL.Errors.Errors Query 29 | 30 | 31 | type alias Query = 32 | { binary : Data.Binary.Binary 33 | , userType : GraphQL.Enum.UserType.UserType 34 | } 35 | 36 | 37 | queryDecoder : Json.Decode.Decoder Query 38 | queryDecoder = 39 | Json.Decode.map2 Query 40 | (Json.Decode.field "binary" Data.Binary.decoder) 41 | (Json.Decode.field "userType" GraphQL.Enum.UserType.decoder) 42 | -------------------------------------------------------------------------------- /tests/gen/fixtures/names/queries.gql: -------------------------------------------------------------------------------- 1 | # query NAMES_UPPER { 2 | # NAMES_UPPER 3 | # } 4 | 5 | # query names_lower { 6 | # names_lower 7 | # } 8 | 9 | # query names_lowerAndUpper { 10 | # names_lowerAndUpper 11 | # } 12 | 13 | query UserName { 14 | user { 15 | name 16 | } 17 | } 18 | 19 | query UserEmail { 20 | user { 21 | email 22 | } 23 | } 24 | 25 | query Node($ID_UPPER: ID!, $id_lower: ID!, $id_lowerAndUpper: ID!) { 26 | NODE_UPPER(ID_UPPER: $ID_UPPER) { 27 | ... on User { 28 | name 29 | } 30 | } 31 | node_lower(id_lower: $id_lower) { 32 | ... on User { 33 | name 34 | } 35 | ... on Group { 36 | name 37 | __typename 38 | } 39 | } 40 | node_lowerAndUpper(id_lowerAndUpper: $id_lowerAndUpper) { 41 | ... on User { 42 | id 43 | email 44 | } 45 | ... on Group { 46 | id 47 | } 48 | } 49 | } 50 | 51 | query Underscores { 52 | _UNDERSCORE_UPPER 53 | _DOUBLE__UNDERSCORE__UPPER 54 | _TRIPPLE___UNDERSCORE___UPPER 55 | _underscore_lower 56 | _underscore_lowerAndUpper 57 | } 58 | -------------------------------------------------------------------------------- /examples/features/src-generated/Queries/Aliases.elm: -------------------------------------------------------------------------------- 1 | module Queries.Aliases exposing 2 | ( Query 3 | , Response 4 | , query 5 | ) 6 | 7 | import GraphQL.Errors 8 | import GraphQL.Operation 9 | import GraphQL.Response 10 | import Json.Decode 11 | 12 | 13 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 14 | query = 15 | GraphQL.Operation.withQuery 16 | """{ 17 | en: translation(id: "hello.world", language: EN) 18 | nl: translation(id: "hello.world", language: NL) 19 | }""" 20 | Maybe.Nothing 21 | queryDecoder 22 | GraphQL.Errors.decoder 23 | 24 | 25 | type alias Response = 26 | GraphQL.Response.Response GraphQL.Errors.Errors Query 27 | 28 | 29 | type alias Query = 30 | { en : Maybe.Maybe String 31 | , nl : Maybe.Maybe String 32 | } 33 | 34 | 35 | queryDecoder : Json.Decode.Decoder Query 36 | queryDecoder = 37 | Json.Decode.map2 Query 38 | (Json.Decode.field "en" (Json.Decode.nullable Json.Decode.string)) 39 | (Json.Decode.field "nl" (Json.Decode.nullable Json.Decode.string)) 40 | -------------------------------------------------------------------------------- /tests/gen/fixtures/names/schema.gql: -------------------------------------------------------------------------------- 1 | # Enums 2 | 3 | enum NAMES_UPPER { 4 | ONE 5 | TWO 6 | FOURTY_TWO 7 | } 8 | 9 | enum names_lower { 10 | one 11 | two 12 | fourty_two 13 | } 14 | 15 | enum names_lowerAndUpper { 16 | oneAndTwo 17 | twoOrTwenty_even 18 | fourtyTwo 19 | } 20 | 21 | # Schema 22 | 23 | schema { 24 | query: Query 25 | } 26 | 27 | # Query 28 | 29 | type Query { 30 | # NAMES_UPPER: NAMES_UPPER 31 | # names_lower: names_lower! 32 | # names_lowerAndUpper: names_lowerAndUpper! 33 | user: User! 34 | NODE_UPPER(ID_UPPER: ID!): Node 35 | node_lower(id_lower: ID!): Node 36 | node_lowerAndUpper(id_lowerAndUpper: ID!): Node 37 | _UNDERSCORE_UPPER: String! 38 | _DOUBLE__UNDERSCORE__UPPER: String! 39 | _TRIPPLE___UNDERSCORE___UPPER: String! 40 | _underscore_lower: String! 41 | _underscore_lowerAndUpper: String! 42 | } 43 | 44 | interface Node { 45 | id: ID! 46 | } 47 | 48 | type User implements Node { 49 | id: ID! 50 | name: String! 51 | email: String! 52 | group: Group 53 | } 54 | 55 | type Group implements Node { 56 | id: ID! 57 | name: String! 58 | } 59 | -------------------------------------------------------------------------------- /tests/gen/fixtures/customScalars/expected-output/CustomNullableScalarTypes.elm: -------------------------------------------------------------------------------- 1 | module CustomNullableScalarTypes exposing 2 | ( Query 3 | , Response 4 | , query 5 | ) 6 | 7 | import Data.Id 8 | import Data.Time 9 | import GraphQL.Errors 10 | import GraphQL.Operation 11 | import GraphQL.Response 12 | import Json.Decode 13 | 14 | 15 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 16 | query = 17 | GraphQL.Operation.withQuery 18 | """{ 19 | idOrNull 20 | timeOrNull 21 | }""" 22 | Maybe.Nothing 23 | queryDecoder 24 | GraphQL.Errors.decoder 25 | 26 | 27 | type alias Response = 28 | GraphQL.Response.Response GraphQL.Errors.Errors Query 29 | 30 | 31 | type alias Query = 32 | { idOrNull : Maybe.Maybe Data.Id.Id 33 | , timeOrNull : Maybe.Maybe Data.Time.Posix 34 | } 35 | 36 | 37 | queryDecoder : Json.Decode.Decoder Query 38 | queryDecoder = 39 | Json.Decode.map2 Query 40 | (Json.Decode.field "idOrNull" (Json.Decode.nullable Data.Id.decoder)) 41 | (Json.Decode.field "timeOrNull" (Json.Decode.nullable Data.Time.decoder)) 42 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | } 6 | 7 | # Query 8 | 9 | type Query { 10 | scalars(string: String!, int: Int!): String 11 | 12 | scalarsOptional(string: String, int: Int): String 13 | 14 | scalarsMixed(string: String, int: Int!): String 15 | 16 | inputs(inputs: Inputs!): String 17 | 18 | inputsOptional(inputs: OptionalInputs): String 19 | 20 | inputsMixed(inputs: MixedInputs!, inputs2: MixedInputs): String 21 | 22 | inputsMultiple(inputs: Inputs!, inputs2: Inputs): String 23 | 24 | lists( 25 | ints: [Int!] 26 | floats: [Float] 27 | inputs: [Inputs!]! 28 | inputs2: [OptionalInputs]! 29 | ): String 30 | 31 | recursive(input: RecursiveInput!): String 32 | } 33 | 34 | input Inputs { 35 | int: Int! 36 | float: Float! 37 | other: OtherInputs! 38 | } 39 | 40 | input OptionalInputs { 41 | int: Int 42 | float: Float 43 | other: OtherInputs 44 | } 45 | 46 | input MixedInputs { 47 | int: Int! 48 | float: Float 49 | other: OtherInputs! 50 | } 51 | 52 | input OtherInputs { 53 | string: String! 54 | } 55 | 56 | input RecursiveInput { 57 | child: RecursiveInput 58 | } 59 | -------------------------------------------------------------------------------- /examples/basic/src-generated/Queries/Messages.elm: -------------------------------------------------------------------------------- 1 | module Queries.Messages exposing 2 | ( Message 3 | , Query 4 | , Response 5 | , query 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | 13 | 14 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 15 | query = 16 | GraphQL.Operation.withQuery 17 | """{ 18 | messages { 19 | message 20 | } 21 | }""" 22 | Maybe.Nothing 23 | queryDecoder 24 | GraphQL.Errors.decoder 25 | 26 | 27 | type alias Response = 28 | GraphQL.Response.Response GraphQL.Errors.Errors Query 29 | 30 | 31 | type alias Query = 32 | { messages : List Message 33 | } 34 | 35 | 36 | queryDecoder : Json.Decode.Decoder Query 37 | queryDecoder = 38 | Json.Decode.map Query 39 | (Json.Decode.field "messages" (Json.Decode.list messageDecoder)) 40 | 41 | 42 | type alias Message = 43 | { message : String 44 | } 45 | 46 | 47 | messageDecoder : Json.Decode.Decoder Message 48 | messageDecoder = 49 | Json.Decode.map Message 50 | (Json.Decode.field "message" Json.Decode.string) 51 | -------------------------------------------------------------------------------- /examples/readme/src-generated/MyQuery.elm: -------------------------------------------------------------------------------- 1 | module MyQuery exposing 2 | ( User 3 | , UserNameQuery 4 | , UserNameResponse 5 | , userName 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | 13 | 14 | userName : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors UserNameQuery 15 | userName = 16 | GraphQL.Operation.withQuery 17 | """query UserName { 18 | user { 19 | name 20 | } 21 | }""" 22 | Maybe.Nothing 23 | userNameQueryDecoder 24 | GraphQL.Errors.decoder 25 | 26 | 27 | type alias UserNameResponse = 28 | GraphQL.Response.Response GraphQL.Errors.Errors UserNameQuery 29 | 30 | 31 | type alias UserNameQuery = 32 | { user : User 33 | } 34 | 35 | 36 | userNameQueryDecoder : Json.Decode.Decoder UserNameQuery 37 | userNameQueryDecoder = 38 | Json.Decode.map UserNameQuery 39 | (Json.Decode.field "user" userDecoder) 40 | 41 | 42 | type alias User = 43 | { name : String 44 | } 45 | 46 | 47 | userDecoder : Json.Decode.Decoder User 48 | userDecoder = 49 | Json.Decode.map User 50 | (Json.Decode.field "name" Json.Decode.string) 51 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations/expected-output/AnonymousQuery.elm: -------------------------------------------------------------------------------- 1 | module AnonymousQuery exposing 2 | ( Operation 3 | , Query 4 | , Response 5 | , query 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | 13 | 14 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 15 | query = 16 | GraphQL.Operation.withQuery 17 | """{ 18 | operation { 19 | query 20 | } 21 | }""" 22 | Maybe.Nothing 23 | queryDecoder 24 | GraphQL.Errors.decoder 25 | 26 | 27 | type alias Response = 28 | GraphQL.Response.Response GraphQL.Errors.Errors Query 29 | 30 | 31 | type alias Query = 32 | { operation : Maybe.Maybe Operation 33 | } 34 | 35 | 36 | queryDecoder : Json.Decode.Decoder Query 37 | queryDecoder = 38 | Json.Decode.map Query 39 | (Json.Decode.field "operation" (Json.Decode.nullable operationDecoder)) 40 | 41 | 42 | type alias Operation = 43 | { query : String 44 | } 45 | 46 | 47 | operationDecoder : Json.Decode.Decoder Operation 48 | operationDecoder = 49 | Json.Decode.map Operation 50 | (Json.Decode.field "query" Json.Decode.string) 51 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/expected-output/Basic.elm: -------------------------------------------------------------------------------- 1 | module Basic exposing 2 | ( Person 3 | , Query 4 | , Response 5 | , query 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | 13 | 14 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 15 | query = 16 | GraphQL.Operation.withQuery 17 | """{ 18 | i { 19 | name 20 | age 21 | } 22 | }""" 23 | Maybe.Nothing 24 | queryDecoder 25 | GraphQL.Errors.decoder 26 | 27 | 28 | type alias Response = 29 | GraphQL.Response.Response GraphQL.Errors.Errors Query 30 | 31 | 32 | type alias Query = 33 | { i : Person 34 | } 35 | 36 | 37 | queryDecoder : Json.Decode.Decoder Query 38 | queryDecoder = 39 | Json.Decode.map Query 40 | (Json.Decode.field "i" personDecoder) 41 | 42 | 43 | type alias Person = 44 | { name : String 45 | , age : Maybe.Maybe Int 46 | } 47 | 48 | 49 | personDecoder : Json.Decode.Decoder Person 50 | personDecoder = 51 | Json.Decode.map2 Person 52 | (Json.Decode.field "name" Json.Decode.string) 53 | (Json.Decode.field "age" (Json.Decode.nullable Json.Decode.int)) 54 | -------------------------------------------------------------------------------- /tests/gen/fixtures/fragments/query.gql: -------------------------------------------------------------------------------- 1 | query Fragments($id: String!) { 2 | user1: user { 3 | ...fields 4 | } 5 | user2: user { 6 | ...fields 7 | } 8 | user3: userOrNull { 9 | ...fields 10 | } 11 | user4: userById(id: $id) { 12 | ...fields 13 | } 14 | user5: user { 15 | email 16 | ...userId 17 | ...userName 18 | ...userAndProfile 19 | ...userProfile 20 | profile { 21 | ...profileName 22 | } 23 | } 24 | 25 | flip { 26 | ...heads 27 | ... on Tails { 28 | length 29 | } 30 | } 31 | } 32 | 33 | fragment fields on User { 34 | id 35 | name 36 | email 37 | } 38 | 39 | fragment userId on User { 40 | id 41 | } 42 | 43 | fragment userName on User { 44 | name 45 | } 46 | 47 | fragment userAndProfile on User { 48 | name 49 | email 50 | profile { 51 | ...profileImage 52 | } 53 | } 54 | 55 | fragment userProfile on User { 56 | profile { 57 | ...profileId 58 | name 59 | image 60 | } 61 | } 62 | 63 | fragment profileId on Profile { 64 | id 65 | } 66 | 67 | fragment profileName on Profile { 68 | name 69 | } 70 | 71 | fragment profileImage on Profile { 72 | image 73 | } 74 | 75 | fragment heads on Heads { 76 | name 77 | } 78 | -------------------------------------------------------------------------------- /tests/gen/fixtures/scalars/expected-output/DefaultScalarTypes.elm: -------------------------------------------------------------------------------- 1 | module DefaultScalarTypes exposing 2 | ( Query 3 | , Response 4 | , query 5 | ) 6 | 7 | import GraphQL.Errors 8 | import GraphQL.Operation 9 | import GraphQL.Response 10 | import Json.Decode 11 | 12 | 13 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 14 | query = 15 | GraphQL.Operation.withQuery 16 | """{ 17 | int 18 | float 19 | string 20 | boolean 21 | id 22 | }""" 23 | Maybe.Nothing 24 | queryDecoder 25 | GraphQL.Errors.decoder 26 | 27 | 28 | type alias Response = 29 | GraphQL.Response.Response GraphQL.Errors.Errors Query 30 | 31 | 32 | type alias Query = 33 | { int : Int 34 | , float : Float 35 | , string : String 36 | , boolean : Bool 37 | , id : String 38 | } 39 | 40 | 41 | queryDecoder : Json.Decode.Decoder Query 42 | queryDecoder = 43 | Json.Decode.map5 Query 44 | (Json.Decode.field "int" Json.Decode.int) 45 | (Json.Decode.field "float" Json.Decode.float) 46 | (Json.Decode.field "string" Json.Decode.string) 47 | (Json.Decode.field "boolean" Json.Decode.bool) 48 | (Json.Decode.field "id" Json.Decode.string) 49 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations/expected-output/AnonymousMutation.elm: -------------------------------------------------------------------------------- 1 | module AnonymousMutation exposing 2 | ( Fragment 3 | , Mutation 4 | , Response 5 | , mutation 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | 13 | 14 | mutation : GraphQL.Operation.Operation GraphQL.Operation.Mutation GraphQL.Errors.Errors Mutation 15 | mutation = 16 | GraphQL.Operation.withQuery 17 | """mutation { 18 | fragment { 19 | name 20 | } 21 | }""" 22 | Maybe.Nothing 23 | mutationDecoder 24 | GraphQL.Errors.decoder 25 | 26 | 27 | type alias Response = 28 | GraphQL.Response.Response GraphQL.Errors.Errors Mutation 29 | 30 | 31 | type alias Mutation = 32 | { fragment : Maybe.Maybe Fragment 33 | } 34 | 35 | 36 | mutationDecoder : Json.Decode.Decoder Mutation 37 | mutationDecoder = 38 | Json.Decode.map Mutation 39 | (Json.Decode.field "fragment" (Json.Decode.nullable fragmentDecoder)) 40 | 41 | 42 | type alias Fragment = 43 | { name : String 44 | } 45 | 46 | 47 | fragmentDecoder : Json.Decode.Decoder Fragment 48 | fragmentDecoder = 49 | Json.Decode.map Fragment 50 | (Json.Decode.field "name" Json.Decode.string) 51 | -------------------------------------------------------------------------------- /examples/features/src-generated/GraphQL/Enum/Language.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.Language exposing 2 | ( Language(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type Language 14 | = En 15 | | Nl 16 | 17 | 18 | encode : Language -> Json.Encode.Value 19 | encode value = 20 | Json.Encode.string (toString value) 21 | 22 | 23 | decoder : Json.Decode.Decoder Language 24 | decoder = 25 | Json.Decode.string 26 | |> Json.Decode.andThen 27 | (\value -> 28 | value 29 | |> fromString 30 | |> Maybe.map Json.Decode.succeed 31 | |> Maybe.withDefault 32 | (Json.Decode.fail <| "unknown Language " ++ value) 33 | ) 34 | 35 | 36 | toString : Language -> String 37 | toString value = 38 | case value of 39 | En -> 40 | "EN" 41 | 42 | Nl -> 43 | "NL" 44 | 45 | 46 | fromString : String -> Maybe Language 47 | fromString value = 48 | case value of 49 | "EN" -> 50 | Just En 51 | 52 | "NL" -> 53 | Just Nl 54 | 55 | _ -> 56 | Nothing 57 | -------------------------------------------------------------------------------- /tests/gen/fixtures/enums/expected-output/GraphQL/Enum/Binary.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.Binary exposing 2 | ( Binary(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type Binary 14 | = Zero 15 | | One 16 | 17 | 18 | encode : Binary -> Json.Encode.Value 19 | encode value = 20 | Json.Encode.string (toString value) 21 | 22 | 23 | decoder : Json.Decode.Decoder Binary 24 | decoder = 25 | Json.Decode.string 26 | |> Json.Decode.andThen 27 | (\value -> 28 | value 29 | |> fromString 30 | |> Maybe.map Json.Decode.succeed 31 | |> Maybe.withDefault 32 | (Json.Decode.fail <| "unknown Binary " ++ value) 33 | ) 34 | 35 | 36 | toString : Binary -> String 37 | toString value = 38 | case value of 39 | Zero -> 40 | "ZERO" 41 | 42 | One -> 43 | "ONE" 44 | 45 | 46 | fromString : String -> Maybe Binary 47 | fromString value = 48 | case value of 49 | "ZERO" -> 50 | Just Zero 51 | 52 | "ONE" -> 53 | Just One 54 | 55 | _ -> 56 | Nothing 57 | -------------------------------------------------------------------------------- /examples/basic2/server.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | const { readFileSync } = require("fs"); 4 | const express = require("express"); 5 | const { ApolloServer, gql } = require("apollo-server-express"); 6 | 7 | const messages = []; 8 | 9 | const typeDefs = gql(readFileSync("src/schema.gql", "utf8")); 10 | 11 | const resolvers = { 12 | Query: { 13 | messages: () => messages, 14 | }, 15 | 16 | Mutation: { 17 | postMessage: (obj, args) => { 18 | if (!args.message || args.message.trim() === "") { 19 | return { error: "message cannot be empty" }; 20 | } 21 | 22 | const message = { 23 | id: messages.length, 24 | message: args.message, 25 | }; 26 | messages.push(message); 27 | return message; 28 | }, 29 | }, 30 | 31 | PostMessageResponse: { 32 | __resolveType: (data) => (data.error ? "MutationError" : "Message"), 33 | }, 34 | }; 35 | 36 | const server = new ApolloServer({ 37 | typeDefs, 38 | resolvers, 39 | }); 40 | 41 | const app = express(); 42 | server.start().then(() => { 43 | server.applyMiddleware({ app }); 44 | app.use(express.static(__dirname)); 45 | app.listen(3000); 46 | 47 | console.log("example : http://localhost:3000"); 48 | console.log("playground : http://localhost:3000/graphql"); 49 | }); 50 | -------------------------------------------------------------------------------- /tests/gen/fixtures/customScalars/expected-output/CustomScalarInput.elm: -------------------------------------------------------------------------------- 1 | module CustomScalarInput exposing 2 | ( AtQuery 3 | , AtResponse 4 | , AtVariables 5 | , at 6 | ) 7 | 8 | import Data.Time 9 | import GraphQL.Errors 10 | import GraphQL.Operation 11 | import GraphQL.Response 12 | import Json.Decode 13 | import Json.Encode 14 | 15 | 16 | at : AtVariables -> GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors AtQuery 17 | at variables = 18 | GraphQL.Operation.withQuery 19 | """query At($time: Time!) { 20 | at(time: $time) 21 | }""" 22 | (Maybe.Just <| encodeAtVariables variables) 23 | atQueryDecoder 24 | GraphQL.Errors.decoder 25 | 26 | 27 | type alias AtResponse = 28 | GraphQL.Response.Response GraphQL.Errors.Errors AtQuery 29 | 30 | 31 | type alias AtVariables = 32 | { time : Data.Time.Posix 33 | } 34 | 35 | 36 | encodeAtVariables : AtVariables -> Json.Encode.Value 37 | encodeAtVariables inputs = 38 | Json.Encode.object 39 | [ ( "time", Data.Time.encode inputs.time ) 40 | ] 41 | 42 | 43 | type alias AtQuery = 44 | { at : Maybe.Maybe Int 45 | } 46 | 47 | 48 | atQueryDecoder : Json.Decode.Decoder AtQuery 49 | atQueryDecoder = 50 | Json.Decode.map AtQuery 51 | (Json.Decode.field "at" (Json.Decode.nullable Json.Decode.int)) 52 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/expected-output/InterfacePlain.elm: -------------------------------------------------------------------------------- 1 | module InterfacePlain exposing 2 | ( Animal 3 | , InterfacePlainQuery 4 | , InterfacePlainResponse 5 | , interfacePlain 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | 13 | 14 | interfacePlain : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors InterfacePlainQuery 15 | interfacePlain = 16 | GraphQL.Operation.withQuery 17 | """query InterfacePlain { 18 | animal { 19 | color 20 | } 21 | }""" 22 | Maybe.Nothing 23 | interfacePlainQueryDecoder 24 | GraphQL.Errors.decoder 25 | 26 | 27 | type alias InterfacePlainResponse = 28 | GraphQL.Response.Response GraphQL.Errors.Errors InterfacePlainQuery 29 | 30 | 31 | type alias InterfacePlainQuery = 32 | { animal : Animal 33 | } 34 | 35 | 36 | interfacePlainQueryDecoder : Json.Decode.Decoder InterfacePlainQuery 37 | interfacePlainQueryDecoder = 38 | Json.Decode.map InterfacePlainQuery 39 | (Json.Decode.field "animal" animalDecoder) 40 | 41 | 42 | type alias Animal = 43 | { color : String 44 | } 45 | 46 | 47 | animalDecoder : Json.Decode.Decoder Animal 48 | animalDecoder = 49 | Json.Decode.map Animal 50 | (Json.Decode.field "color" Json.Decode.string) 51 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/expected-output/SameTypeSameFields.elm: -------------------------------------------------------------------------------- 1 | module SameTypeSameFields exposing 2 | ( Person 3 | , Query 4 | , Response 5 | , query 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | 13 | 14 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 15 | query = 16 | GraphQL.Operation.withQuery 17 | """{ 18 | i { 19 | name 20 | age 21 | } 22 | me { 23 | age 24 | name 25 | } 26 | }""" 27 | Maybe.Nothing 28 | queryDecoder 29 | GraphQL.Errors.decoder 30 | 31 | 32 | type alias Response = 33 | GraphQL.Response.Response GraphQL.Errors.Errors Query 34 | 35 | 36 | type alias Query = 37 | { i : Person 38 | , me : Person 39 | } 40 | 41 | 42 | queryDecoder : Json.Decode.Decoder Query 43 | queryDecoder = 44 | Json.Decode.map2 Query 45 | (Json.Decode.field "i" personDecoder) 46 | (Json.Decode.field "me" personDecoder) 47 | 48 | 49 | type alias Person = 50 | { name : String 51 | , age : Maybe.Maybe Int 52 | } 53 | 54 | 55 | personDecoder : Json.Decode.Decoder Person 56 | personDecoder = 57 | Json.Decode.map2 Person 58 | (Json.Decode.field "name" Json.Decode.string) 59 | (Json.Decode.field "age" (Json.Decode.nullable Json.Decode.int)) 60 | -------------------------------------------------------------------------------- /tests/gen/fixtures/names/expected-output/GraphQL/Enum/NamesUpper.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.NamesUpper exposing 2 | ( NamesUpper(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type NamesUpper 14 | = One 15 | | Two 16 | | FourtyTwo 17 | 18 | 19 | encode : NamesUpper -> Json.Encode.Value 20 | encode value = 21 | Json.Encode.string (toString value) 22 | 23 | 24 | decoder : Json.Decode.Decoder NamesUpper 25 | decoder = 26 | Json.Decode.string 27 | |> Json.Decode.andThen 28 | (\value -> 29 | value 30 | |> fromString 31 | |> Maybe.map Json.Decode.succeed 32 | |> Maybe.withDefault 33 | (Json.Decode.fail <| "unknown NamesUpper " ++ value) 34 | ) 35 | 36 | 37 | toString : NamesUpper -> String 38 | toString value = 39 | case value of 40 | One -> 41 | "ONE" 42 | 43 | Two -> 44 | "TWO" 45 | 46 | FourtyTwo -> 47 | "FOURTY_TWO" 48 | 49 | 50 | fromString : String -> Maybe NamesUpper 51 | fromString value = 52 | case value of 53 | "ONE" -> 54 | Just One 55 | 56 | "TWO" -> 57 | Just Two 58 | 59 | "FOURTY_TWO" -> 60 | Just FourtyTwo 61 | 62 | _ -> 63 | Nothing 64 | -------------------------------------------------------------------------------- /tests/gen/fixtures/names/expected-output/GraphQL/Enum/Names_lower.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.Names_lower exposing 2 | ( Names_lower(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type Names_lower 14 | = One 15 | | Two 16 | | Fourty_two 17 | 18 | 19 | encode : Names_lower -> Json.Encode.Value 20 | encode value = 21 | Json.Encode.string (toString value) 22 | 23 | 24 | decoder : Json.Decode.Decoder Names_lower 25 | decoder = 26 | Json.Decode.string 27 | |> Json.Decode.andThen 28 | (\value -> 29 | value 30 | |> fromString 31 | |> Maybe.map Json.Decode.succeed 32 | |> Maybe.withDefault 33 | (Json.Decode.fail <| "unknown Names_lower " ++ value) 34 | ) 35 | 36 | 37 | toString : Names_lower -> String 38 | toString value = 39 | case value of 40 | One -> 41 | "one" 42 | 43 | Two -> 44 | "two" 45 | 46 | Fourty_two -> 47 | "fourty_two" 48 | 49 | 50 | fromString : String -> Maybe Names_lower 51 | fromString value = 52 | case value of 53 | "one" -> 54 | Just One 55 | 56 | "two" -> 57 | Just Two 58 | 59 | "fourty_two" -> 60 | Just Fourty_two 61 | 62 | _ -> 63 | Nothing 64 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/expected-output/SameTypeSameFieldsNullable.elm: -------------------------------------------------------------------------------- 1 | module SameTypeSameFieldsNullable exposing 2 | ( Person2 3 | , Query 4 | , Response 5 | , query 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | 13 | 14 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 15 | query = 16 | GraphQL.Operation.withQuery 17 | """{ 18 | you { 19 | email 20 | age 21 | } 22 | youOrNull { 23 | age 24 | email 25 | } 26 | }""" 27 | Maybe.Nothing 28 | queryDecoder 29 | GraphQL.Errors.decoder 30 | 31 | 32 | type alias Response = 33 | GraphQL.Response.Response GraphQL.Errors.Errors Query 34 | 35 | 36 | type alias Query = 37 | { you : Person2 38 | , youOrNull : Maybe.Maybe Person2 39 | } 40 | 41 | 42 | queryDecoder : Json.Decode.Decoder Query 43 | queryDecoder = 44 | Json.Decode.map2 Query 45 | (Json.Decode.field "you" person2Decoder) 46 | (Json.Decode.field "youOrNull" (Json.Decode.nullable person2Decoder)) 47 | 48 | 49 | type alias Person2 = 50 | { email : Maybe.Maybe String 51 | , age : Maybe.Maybe Int 52 | } 53 | 54 | 55 | person2Decoder : Json.Decode.Decoder Person2 56 | person2Decoder = 57 | Json.Decode.map2 Person2 58 | (Json.Decode.field "email" (Json.Decode.nullable Json.Decode.string)) 59 | (Json.Decode.field "age" (Json.Decode.nullable Json.Decode.int)) 60 | -------------------------------------------------------------------------------- /tests/gen/fixtures/lists/expected-output/ListOfScalars.elm: -------------------------------------------------------------------------------- 1 | module ListOfScalars exposing 2 | ( Query 3 | , Response 4 | , query 5 | ) 6 | 7 | import GraphQL.Errors 8 | import GraphQL.Operation 9 | import GraphQL.Response 10 | import Json.Decode 11 | 12 | 13 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 14 | query = 15 | GraphQL.Operation.withQuery 16 | """{ 17 | pets_pet 18 | pets_petOrNull 19 | petsOrNull_pet 20 | petsOrNull_petOrNull 21 | }""" 22 | Maybe.Nothing 23 | queryDecoder 24 | GraphQL.Errors.decoder 25 | 26 | 27 | type alias Response = 28 | GraphQL.Response.Response GraphQL.Errors.Errors Query 29 | 30 | 31 | type alias Query = 32 | { pets_pet : List String 33 | , pets_petOrNull : List (Maybe.Maybe String) 34 | , petsOrNull_pet : Maybe.Maybe (List String) 35 | , petsOrNull_petOrNull : Maybe.Maybe (List (Maybe.Maybe String)) 36 | } 37 | 38 | 39 | queryDecoder : Json.Decode.Decoder Query 40 | queryDecoder = 41 | Json.Decode.map4 Query 42 | (Json.Decode.field "pets_pet" (Json.Decode.list Json.Decode.string)) 43 | (Json.Decode.field "pets_petOrNull" (Json.Decode.list (Json.Decode.nullable Json.Decode.string))) 44 | (Json.Decode.field "petsOrNull_pet" (Json.Decode.nullable (Json.Decode.list Json.Decode.string))) 45 | (Json.Decode.field "petsOrNull_petOrNull" (Json.Decode.nullable (Json.Decode.list (Json.Decode.nullable Json.Decode.string)))) 46 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/expected-output/Single.elm: -------------------------------------------------------------------------------- 1 | module Single exposing 2 | ( Animal 3 | , SingleQuery 4 | , SingleResponse 5 | , single 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | 13 | 14 | single : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors SingleQuery 15 | single = 16 | GraphQL.Operation.withQuery 17 | """query Single { 18 | single: animal { 19 | ... on Animal { 20 | color 21 | size 22 | } 23 | } 24 | shared: animal { 25 | size 26 | ... on Animal { 27 | color 28 | } 29 | } 30 | }""" 31 | Maybe.Nothing 32 | singleQueryDecoder 33 | GraphQL.Errors.decoder 34 | 35 | 36 | type alias SingleResponse = 37 | GraphQL.Response.Response GraphQL.Errors.Errors SingleQuery 38 | 39 | 40 | type alias SingleQuery = 41 | { single : Animal 42 | , shared : Animal 43 | } 44 | 45 | 46 | singleQueryDecoder : Json.Decode.Decoder SingleQuery 47 | singleQueryDecoder = 48 | Json.Decode.map2 SingleQuery 49 | (Json.Decode.field "single" animalDecoder) 50 | (Json.Decode.field "shared" animalDecoder) 51 | 52 | 53 | type alias Animal = 54 | { color : String 55 | , size : Float 56 | } 57 | 58 | 59 | animalDecoder : Json.Decode.Decoder Animal 60 | animalDecoder = 61 | Json.Decode.map2 Animal 62 | (Json.Decode.field "color" Json.Decode.string) 63 | (Json.Decode.field "size" Json.Decode.float) 64 | -------------------------------------------------------------------------------- /tests/gen/fixtures/scalars/expected-output/DefaultNullableScalarTypes.elm: -------------------------------------------------------------------------------- 1 | module DefaultNullableScalarTypes exposing 2 | ( Query 3 | , Response 4 | , query 5 | ) 6 | 7 | import GraphQL.Errors 8 | import GraphQL.Operation 9 | import GraphQL.Response 10 | import Json.Decode 11 | 12 | 13 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 14 | query = 15 | GraphQL.Operation.withQuery 16 | """{ 17 | intOrNull 18 | floatOrNull 19 | stringOrNull 20 | booleanOrNull 21 | idOrNull 22 | }""" 23 | Maybe.Nothing 24 | queryDecoder 25 | GraphQL.Errors.decoder 26 | 27 | 28 | type alias Response = 29 | GraphQL.Response.Response GraphQL.Errors.Errors Query 30 | 31 | 32 | type alias Query = 33 | { intOrNull : Maybe.Maybe Int 34 | , floatOrNull : Maybe.Maybe Float 35 | , stringOrNull : Maybe.Maybe String 36 | , booleanOrNull : Maybe.Maybe Bool 37 | , idOrNull : Maybe.Maybe String 38 | } 39 | 40 | 41 | queryDecoder : Json.Decode.Decoder Query 42 | queryDecoder = 43 | Json.Decode.map5 Query 44 | (Json.Decode.field "intOrNull" (Json.Decode.nullable Json.Decode.int)) 45 | (Json.Decode.field "floatOrNull" (Json.Decode.nullable Json.Decode.float)) 46 | (Json.Decode.field "stringOrNull" (Json.Decode.nullable Json.Decode.string)) 47 | (Json.Decode.field "booleanOrNull" (Json.Decode.nullable Json.Decode.bool)) 48 | (Json.Decode.field "idOrNull" (Json.Decode.nullable Json.Decode.string)) 49 | -------------------------------------------------------------------------------- /tests/gen/fixtures/enums/expected-output/GraphQL/Enum/UserType.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.UserType exposing 2 | ( UserType(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type UserType 14 | = RegularUser 15 | | AdminUser 16 | | Temp_AdminUser 17 | 18 | 19 | encode : UserType -> Json.Encode.Value 20 | encode value = 21 | Json.Encode.string (toString value) 22 | 23 | 24 | decoder : Json.Decode.Decoder UserType 25 | decoder = 26 | Json.Decode.string 27 | |> Json.Decode.andThen 28 | (\value -> 29 | value 30 | |> fromString 31 | |> Maybe.map Json.Decode.succeed 32 | |> Maybe.withDefault 33 | (Json.Decode.fail <| "unknown UserType " ++ value) 34 | ) 35 | 36 | 37 | toString : UserType -> String 38 | toString value = 39 | case value of 40 | RegularUser -> 41 | "REGULAR_USER" 42 | 43 | AdminUser -> 44 | "ADMIN_USER" 45 | 46 | Temp_AdminUser -> 47 | "TEMP__ADMIN_USER" 48 | 49 | 50 | fromString : String -> Maybe UserType 51 | fromString value = 52 | case value of 53 | "REGULAR_USER" -> 54 | Just RegularUser 55 | 56 | "ADMIN_USER" -> 57 | Just AdminUser 58 | 59 | "TEMP__ADMIN_USER" -> 60 | Just Temp_AdminUser 61 | 62 | _ -> 63 | Nothing 64 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/expected-output/Scalars.elm: -------------------------------------------------------------------------------- 1 | module Scalars exposing 2 | ( ScalarsQuery 3 | , ScalarsResponse 4 | , ScalarsVariables 5 | , scalars 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | import Json.Encode 13 | 14 | 15 | scalars : ScalarsVariables -> GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors ScalarsQuery 16 | scalars variables = 17 | GraphQL.Operation.withQuery 18 | """query Scalars($string: String!, $int: Int!) { 19 | scalars(string: $string, int: $int) 20 | }""" 21 | (Maybe.Just <| encodeScalarsVariables variables) 22 | scalarsQueryDecoder 23 | GraphQL.Errors.decoder 24 | 25 | 26 | type alias ScalarsResponse = 27 | GraphQL.Response.Response GraphQL.Errors.Errors ScalarsQuery 28 | 29 | 30 | type alias ScalarsVariables = 31 | { string : String 32 | , int : Int 33 | } 34 | 35 | 36 | encodeScalarsVariables : ScalarsVariables -> Json.Encode.Value 37 | encodeScalarsVariables inputs = 38 | Json.Encode.object 39 | [ ( "string", Json.Encode.string inputs.string ) 40 | , ( "int", Json.Encode.int inputs.int ) 41 | ] 42 | 43 | 44 | type alias ScalarsQuery = 45 | { scalars : Maybe.Maybe String 46 | } 47 | 48 | 49 | scalarsQueryDecoder : Json.Decode.Decoder ScalarsQuery 50 | scalarsQueryDecoder = 51 | Json.Decode.map ScalarsQuery 52 | (Json.Decode.field "scalars" (Json.Decode.nullable Json.Decode.string)) 53 | -------------------------------------------------------------------------------- /tests/gen/fixtures/keywords/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | } 6 | 7 | # Query 8 | 9 | type Query { 10 | elmKeywords: ElmKeywords! 11 | otherElmKeywords: OtherElmKeywords! 12 | elmBasics: ElmBasics! 13 | boolean: Bool! 14 | list: [List!]! 15 | graphqlToElmReservedWords: GraphqlToElmReservedWords! 16 | misc: Misc! 17 | } 18 | 19 | type ElmKeywords { 20 | as: String! 21 | case: Boolean! 22 | else: Int! 23 | exposing: Float! 24 | if: [String!]! 25 | import: String! 26 | in: String! 27 | let: String! 28 | module: String! 29 | of: String! 30 | port: String! 31 | then: String! 32 | type: String! 33 | where: String! 34 | } 35 | 36 | type OtherElmKeywords { 37 | alias: String! 38 | command: String! 39 | effect: String! 40 | false: String! 41 | infix: String! 42 | left: String! 43 | non: String! 44 | null: String! 45 | right: String! 46 | subscription: String! 47 | true: String! 48 | } 49 | 50 | type ElmBasics { 51 | not: String! 52 | flip: String! 53 | String: String! 54 | Int: String! 55 | infix: String! 56 | min: String! 57 | Just: String! 58 | True: String! 59 | } 60 | 61 | type Bool { 62 | is: Int! 63 | } 64 | 65 | type List { 66 | is: Int! 67 | } 68 | 69 | type GraphqlToElmReservedWords { 70 | Variables: String! 71 | Data: String! 72 | query: String! 73 | encodeVariables: String! 74 | decoder: String! 75 | } 76 | 77 | type Misc { 78 | else: String! 79 | else_: String! 80 | type_: String! 81 | Variables2: String! 82 | decoder2: String! 83 | } 84 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/schema.gql: -------------------------------------------------------------------------------- 1 | # Schema 2 | 3 | schema { 4 | query: Query 5 | } 6 | 7 | # Query 8 | 9 | type Query { 10 | i: Person! 11 | me: Person! 12 | you: Person2! 13 | youOrNull: Person2 14 | comments: [Comment!]! 15 | } 16 | 17 | type Person { 18 | name: String! 19 | age: Int 20 | email: String 21 | dog: Dog 22 | bestFriend: Person2 23 | friends: [Person2] 24 | intel: Intel 25 | intel10: Intel10 26 | } 27 | 28 | type Person2 { 29 | name: String! 30 | age: Int 31 | email: String 32 | } 33 | 34 | type Dog { 35 | name: String 36 | color: String! 37 | } 38 | 39 | type Intel implements Intel10 { 40 | field1: Int! 41 | field2: String! 42 | field3: Float! 43 | field4: [Int!]! 44 | field5: [String!]! 45 | field6: [Float!]! 46 | field7: Int! 47 | field8: String! 48 | field9: Float! 49 | field10: [Int!]! 50 | field11: [String!]! 51 | field12: [Float!]! 52 | } 53 | 54 | type OtherIntel implements Intel10 { 55 | field1: Int! 56 | field2: String! 57 | field3: Float! 58 | field4: [Int!]! 59 | field5: [String!]! 60 | field6: [Float!]! 61 | field7: Int! 62 | field8: String! 63 | field9: Float! 64 | field10: [Int!]! 65 | field11: [String!]! 66 | } 67 | 68 | interface Intel10 { 69 | field1: Int! 70 | field2: String! 71 | field3: Float! 72 | field4: [Int!]! 73 | field5: [String!]! 74 | field6: [Float!]! 75 | field7: Int! 76 | field8: String! 77 | field9: Float! 78 | field10: [Int!]! 79 | } 80 | 81 | type Comment { 82 | message: String! 83 | responses: [Comment!]! 84 | } 85 | -------------------------------------------------------------------------------- /examples/features/src-generated/Queries/Mutations.elm: -------------------------------------------------------------------------------- 1 | module Queries.Mutations exposing 2 | ( PostMessageMutation 3 | , PostMessageResponse 4 | , PostMessageVariables 5 | , postMessage 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | import Json.Encode 13 | 14 | 15 | postMessage : PostMessageVariables -> GraphQL.Operation.Operation GraphQL.Operation.Mutation GraphQL.Errors.Errors PostMessageMutation 16 | postMessage variables = 17 | GraphQL.Operation.withQuery 18 | """mutation PostMessage($message: String!) { 19 | postMessage(message: $message) 20 | }""" 21 | (Maybe.Just <| encodePostMessageVariables variables) 22 | postMessageMutationDecoder 23 | GraphQL.Errors.decoder 24 | 25 | 26 | type alias PostMessageResponse = 27 | GraphQL.Response.Response GraphQL.Errors.Errors PostMessageMutation 28 | 29 | 30 | type alias PostMessageVariables = 31 | { message : String 32 | } 33 | 34 | 35 | encodePostMessageVariables : PostMessageVariables -> Json.Encode.Value 36 | encodePostMessageVariables inputs = 37 | Json.Encode.object 38 | [ ( "message", Json.Encode.string inputs.message ) 39 | ] 40 | 41 | 42 | type alias PostMessageMutation = 43 | { postMessage : Maybe.Maybe String 44 | } 45 | 46 | 47 | postMessageMutationDecoder : Json.Decode.Decoder PostMessageMutation 48 | postMessageMutationDecoder = 49 | Json.Decode.map PostMessageMutation 50 | (Json.Decode.field "postMessage" (Json.Decode.nullable Json.Decode.string)) 51 | -------------------------------------------------------------------------------- /tests/gen/fixtures/names/expected-output/GraphQL/Enum/Names_lowerAndUpper.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.Names_lowerAndUpper exposing 2 | ( Names_lowerAndUpper(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type Names_lowerAndUpper 14 | = OneAndTwo 15 | | TwoOrTwenty_even 16 | | FourtyTwo 17 | 18 | 19 | encode : Names_lowerAndUpper -> Json.Encode.Value 20 | encode value = 21 | Json.Encode.string (toString value) 22 | 23 | 24 | decoder : Json.Decode.Decoder Names_lowerAndUpper 25 | decoder = 26 | Json.Decode.string 27 | |> Json.Decode.andThen 28 | (\value -> 29 | value 30 | |> fromString 31 | |> Maybe.map Json.Decode.succeed 32 | |> Maybe.withDefault 33 | (Json.Decode.fail <| "unknown Names_lowerAndUpper " ++ value) 34 | ) 35 | 36 | 37 | toString : Names_lowerAndUpper -> String 38 | toString value = 39 | case value of 40 | OneAndTwo -> 41 | "oneAndTwo" 42 | 43 | TwoOrTwenty_even -> 44 | "twoOrTwenty_even" 45 | 46 | FourtyTwo -> 47 | "fourtyTwo" 48 | 49 | 50 | fromString : String -> Maybe Names_lowerAndUpper 51 | fromString value = 52 | case value of 53 | "oneAndTwo" -> 54 | Just OneAndTwo 55 | 56 | "twoOrTwenty_even" -> 57 | Just TwoOrTwenty_even 58 | 59 | "fourtyTwo" -> 60 | Just FourtyTwo 61 | 62 | _ -> 63 | Nothing 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-present, Harm Boschloo 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | * Neither the name of Harm Boschloo nor the names of other 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /tests/gen/utils/index.ts: -------------------------------------------------------------------------------- 1 | import * as fs from "fs"; 2 | import * as childProcess from "child_process"; 3 | import * as tape from "tape"; 4 | import * as rimrafAsync from "rimraf"; 5 | import * as globAsync from "glob"; 6 | export { Stats } from "fs"; 7 | export { Test } from "tape"; 8 | export { readFile, writeFile, fixLineEndings } from "../../../src/gen/utils"; 9 | 10 | export const test = (name: string, test?: tape.Test): Promise => 11 | new Promise((resolve) => 12 | test ? test.test(name, resolve) : tape(name, resolve) 13 | ); 14 | 15 | export const testNoThrow = ( 16 | test: tape.Test, 17 | message: string 18 | ): Promise => 19 | new Promise((resolve) => test.doesNotThrow(() => resolve(test), message)); 20 | 21 | export const rimraf = (pattern: string): Promise => 22 | new Promise((resolve, reject) => 23 | rimrafAsync(pattern, (error) => (error ? reject(error) : resolve())) 24 | ); 25 | 26 | export const glob = (pattern: string): Promise => 27 | new Promise((resolve, reject) => 28 | globAsync(pattern, (error, matches) => 29 | error ? reject(error) : resolve(matches) 30 | ) 31 | ); 32 | 33 | export const lstat = (path: string): Promise => 34 | new Promise((resolve, reject) => 35 | fs.lstat(path, (error, stats) => (error ? reject(error) : resolve(stats))) 36 | ); 37 | 38 | export const exec = ( 39 | command: string, 40 | options?: childProcess.ExecOptions 41 | ): Promise => 42 | new Promise((resolve, reject) => 43 | childProcess.exec(command, options || {}, (error, stdout) => 44 | error ? reject(error) : resolve(stdout.toString()) 45 | ) 46 | ); 47 | -------------------------------------------------------------------------------- /tests/gen/fixtures/directives/expected-output/Skip.elm: -------------------------------------------------------------------------------- 1 | module Skip exposing 2 | ( SkipQuery 3 | , SkipResponse 4 | , SkipVariables 5 | , skip 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Optional 11 | import GraphQL.Response 12 | import Json.Decode 13 | import Json.Encode 14 | 15 | 16 | skip : SkipVariables -> GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors SkipQuery 17 | skip variables = 18 | GraphQL.Operation.withQuery 19 | """query Skip($withSchool: Boolean!, $withCity: Boolean!) { 20 | name 21 | school @skip(if: $withSchool) 22 | city @skip(if: $withCity) 23 | }""" 24 | (Maybe.Just <| encodeSkipVariables variables) 25 | skipQueryDecoder 26 | GraphQL.Errors.decoder 27 | 28 | 29 | type alias SkipResponse = 30 | GraphQL.Response.Response GraphQL.Errors.Errors SkipQuery 31 | 32 | 33 | type alias SkipVariables = 34 | { withSchool : Bool 35 | , withCity : Bool 36 | } 37 | 38 | 39 | encodeSkipVariables : SkipVariables -> Json.Encode.Value 40 | encodeSkipVariables inputs = 41 | Json.Encode.object 42 | [ ( "withSchool", Json.Encode.bool inputs.withSchool ) 43 | , ( "withCity", Json.Encode.bool inputs.withCity ) 44 | ] 45 | 46 | 47 | type alias SkipQuery = 48 | { name : String 49 | , school : Maybe.Maybe String 50 | , city : GraphQL.Optional.Optional String 51 | } 52 | 53 | 54 | skipQueryDecoder : Json.Decode.Decoder SkipQuery 55 | skipQueryDecoder = 56 | Json.Decode.map3 SkipQuery 57 | (Json.Decode.field "name" Json.Decode.string) 58 | (GraphQL.Optional.nonNullFieldDecoder "school" Json.Decode.string) 59 | (GraphQL.Optional.fieldDecoder "city" Json.Decode.string) 60 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/expected-output/OtherTypeSameFields.elm: -------------------------------------------------------------------------------- 1 | module OtherTypeSameFields exposing 2 | ( Person 3 | , Person2 4 | , Query 5 | , Response 6 | , query 7 | ) 8 | 9 | import GraphQL.Errors 10 | import GraphQL.Operation 11 | import GraphQL.Response 12 | import Json.Decode 13 | 14 | 15 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 16 | query = 17 | GraphQL.Operation.withQuery 18 | """{ 19 | me { 20 | name 21 | email 22 | } 23 | you { 24 | name 25 | email 26 | } 27 | }""" 28 | Maybe.Nothing 29 | queryDecoder 30 | GraphQL.Errors.decoder 31 | 32 | 33 | type alias Response = 34 | GraphQL.Response.Response GraphQL.Errors.Errors Query 35 | 36 | 37 | type alias Query = 38 | { me : Person 39 | , you : Person2 40 | } 41 | 42 | 43 | queryDecoder : Json.Decode.Decoder Query 44 | queryDecoder = 45 | Json.Decode.map2 Query 46 | (Json.Decode.field "me" personDecoder) 47 | (Json.Decode.field "you" person2Decoder) 48 | 49 | 50 | type alias Person = 51 | { name : String 52 | , email : Maybe.Maybe String 53 | } 54 | 55 | 56 | personDecoder : Json.Decode.Decoder Person 57 | personDecoder = 58 | Json.Decode.map2 Person 59 | (Json.Decode.field "name" Json.Decode.string) 60 | (Json.Decode.field "email" (Json.Decode.nullable Json.Decode.string)) 61 | 62 | 63 | type alias Person2 = 64 | { name : String 65 | , email : Maybe.Maybe String 66 | } 67 | 68 | 69 | person2Decoder : Json.Decode.Decoder Person2 70 | person2Decoder = 71 | Json.Decode.map2 Person2 72 | (Json.Decode.field "name" Json.Decode.string) 73 | (Json.Decode.field "email" (Json.Decode.nullable Json.Decode.string)) 74 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/expected-output/SameTypeOtherFields.elm: -------------------------------------------------------------------------------- 1 | module SameTypeOtherFields exposing 2 | ( Person 3 | , Person2 4 | , Query 5 | , Response 6 | , query 7 | ) 8 | 9 | import GraphQL.Errors 10 | import GraphQL.Operation 11 | import GraphQL.Response 12 | import Json.Decode 13 | 14 | 15 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 16 | query = 17 | GraphQL.Operation.withQuery 18 | """{ 19 | i { 20 | name 21 | age 22 | } 23 | me { 24 | email 25 | age 26 | } 27 | }""" 28 | Maybe.Nothing 29 | queryDecoder 30 | GraphQL.Errors.decoder 31 | 32 | 33 | type alias Response = 34 | GraphQL.Response.Response GraphQL.Errors.Errors Query 35 | 36 | 37 | type alias Query = 38 | { i : Person 39 | , me : Person2 40 | } 41 | 42 | 43 | queryDecoder : Json.Decode.Decoder Query 44 | queryDecoder = 45 | Json.Decode.map2 Query 46 | (Json.Decode.field "i" personDecoder) 47 | (Json.Decode.field "me" person2Decoder) 48 | 49 | 50 | type alias Person = 51 | { name : String 52 | , age : Maybe.Maybe Int 53 | } 54 | 55 | 56 | personDecoder : Json.Decode.Decoder Person 57 | personDecoder = 58 | Json.Decode.map2 Person 59 | (Json.Decode.field "name" Json.Decode.string) 60 | (Json.Decode.field "age" (Json.Decode.nullable Json.Decode.int)) 61 | 62 | 63 | type alias Person2 = 64 | { email : Maybe.Maybe String 65 | , age : Maybe.Maybe Int 66 | } 67 | 68 | 69 | person2Decoder : Json.Decode.Decoder Person2 70 | person2Decoder = 71 | Json.Decode.map2 Person2 72 | (Json.Decode.field "email" (Json.Decode.nullable Json.Decode.string)) 73 | (Json.Decode.field "age" (Json.Decode.nullable Json.Decode.int)) 74 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/expected-output/ScalarsMixed.elm: -------------------------------------------------------------------------------- 1 | module ScalarsMixed exposing 2 | ( ScalarsMixedQuery 3 | , ScalarsMixedResponse 4 | , ScalarsMixedVariables 5 | , scalarsMixed 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Optional 11 | import GraphQL.Response 12 | import Json.Decode 13 | import Json.Encode 14 | 15 | 16 | scalarsMixed : ScalarsMixedVariables -> GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors ScalarsMixedQuery 17 | scalarsMixed variables = 18 | GraphQL.Operation.withQuery 19 | """query ScalarsMixed($string: String, $int: Int!) { 20 | scalarsMixed(string: $string, int: $int) 21 | }""" 22 | (Maybe.Just <| encodeScalarsMixedVariables variables) 23 | scalarsMixedQueryDecoder 24 | GraphQL.Errors.decoder 25 | 26 | 27 | type alias ScalarsMixedResponse = 28 | GraphQL.Response.Response GraphQL.Errors.Errors ScalarsMixedQuery 29 | 30 | 31 | type alias ScalarsMixedVariables = 32 | { string : GraphQL.Optional.Optional String 33 | , int : Int 34 | } 35 | 36 | 37 | encodeScalarsMixedVariables : ScalarsMixedVariables -> Json.Encode.Value 38 | encodeScalarsMixedVariables inputs = 39 | GraphQL.Optional.encodeObject 40 | [ ( "string", GraphQL.Optional.map Json.Encode.string inputs.string ) 41 | , ( "int", (Json.Encode.int >> GraphQL.Optional.Present) inputs.int ) 42 | ] 43 | 44 | 45 | type alias ScalarsMixedQuery = 46 | { scalarsMixed : Maybe.Maybe String 47 | } 48 | 49 | 50 | scalarsMixedQueryDecoder : Json.Decode.Decoder ScalarsMixedQuery 51 | scalarsMixedQueryDecoder = 52 | Json.Decode.map ScalarsMixedQuery 53 | (Json.Decode.field "scalarsMixed" (Json.Decode.nullable Json.Decode.string)) 54 | -------------------------------------------------------------------------------- /examples/features/src-generated/Queries/Fields.elm: -------------------------------------------------------------------------------- 1 | module Queries.Fields exposing 2 | ( Message 3 | , Query 4 | , Response 5 | , User 6 | , query 7 | ) 8 | 9 | import GraphQL.Errors 10 | import GraphQL.Operation 11 | import GraphQL.Response 12 | import Json.Decode 13 | 14 | 15 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 16 | query = 17 | GraphQL.Operation.withQuery 18 | """{ 19 | user { 20 | name 21 | email 22 | } 23 | lastMessage { 24 | message 25 | } 26 | messages { 27 | message 28 | } 29 | }""" 30 | Maybe.Nothing 31 | queryDecoder 32 | GraphQL.Errors.decoder 33 | 34 | 35 | type alias Response = 36 | GraphQL.Response.Response GraphQL.Errors.Errors Query 37 | 38 | 39 | type alias Query = 40 | { user : User 41 | , lastMessage : Maybe.Maybe Message 42 | , messages : List Message 43 | } 44 | 45 | 46 | queryDecoder : Json.Decode.Decoder Query 47 | queryDecoder = 48 | Json.Decode.map3 Query 49 | (Json.Decode.field "user" userDecoder) 50 | (Json.Decode.field "lastMessage" (Json.Decode.nullable messageDecoder)) 51 | (Json.Decode.field "messages" (Json.Decode.list messageDecoder)) 52 | 53 | 54 | type alias User = 55 | { name : String 56 | , email : String 57 | } 58 | 59 | 60 | userDecoder : Json.Decode.Decoder User 61 | userDecoder = 62 | Json.Decode.map2 User 63 | (Json.Decode.field "name" Json.Decode.string) 64 | (Json.Decode.field "email" Json.Decode.string) 65 | 66 | 67 | type alias Message = 68 | { message : String 69 | } 70 | 71 | 72 | messageDecoder : Json.Decode.Decoder Message 73 | messageDecoder = 74 | Json.Decode.map Message 75 | (Json.Decode.field "message" Json.Decode.string) 76 | -------------------------------------------------------------------------------- /tests/gen/fixtures/directives/expected-output/Mixed1.elm: -------------------------------------------------------------------------------- 1 | module Mixed1 exposing 2 | ( Mixed1Query 3 | , Mixed1Response 4 | , Mixed1Variables 5 | , mixed1 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Optional 11 | import GraphQL.Response 12 | import Json.Decode 13 | import Json.Encode 14 | 15 | 16 | mixed1 : Mixed1Variables -> GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Mixed1Query 17 | mixed1 variables = 18 | GraphQL.Operation.withQuery 19 | """query Mixed1($withSchool: Boolean!, $withCity: Boolean!) { 20 | name 21 | school @include(if: $withSchool) 22 | city @skip(if: $withCity) 23 | }""" 24 | (Maybe.Just <| encodeMixed1Variables variables) 25 | mixed1QueryDecoder 26 | GraphQL.Errors.decoder 27 | 28 | 29 | type alias Mixed1Response = 30 | GraphQL.Response.Response GraphQL.Errors.Errors Mixed1Query 31 | 32 | 33 | type alias Mixed1Variables = 34 | { withSchool : Bool 35 | , withCity : Bool 36 | } 37 | 38 | 39 | encodeMixed1Variables : Mixed1Variables -> Json.Encode.Value 40 | encodeMixed1Variables inputs = 41 | Json.Encode.object 42 | [ ( "withSchool", Json.Encode.bool inputs.withSchool ) 43 | , ( "withCity", Json.Encode.bool inputs.withCity ) 44 | ] 45 | 46 | 47 | type alias Mixed1Query = 48 | { name : String 49 | , school : Maybe.Maybe String 50 | , city : GraphQL.Optional.Optional String 51 | } 52 | 53 | 54 | mixed1QueryDecoder : Json.Decode.Decoder Mixed1Query 55 | mixed1QueryDecoder = 56 | Json.Decode.map3 Mixed1Query 57 | (Json.Decode.field "name" Json.Decode.string) 58 | (GraphQL.Optional.nonNullFieldDecoder "school" Json.Decode.string) 59 | (GraphQL.Optional.fieldDecoder "city" Json.Decode.string) 60 | -------------------------------------------------------------------------------- /tests/gen/fixtures/directives/expected-output/Mixed2.elm: -------------------------------------------------------------------------------- 1 | module Mixed2 exposing 2 | ( Mixed2Query 3 | , Mixed2Response 4 | , Mixed2Variables 5 | , mixed2 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Optional 11 | import GraphQL.Response 12 | import Json.Decode 13 | import Json.Encode 14 | 15 | 16 | mixed2 : Mixed2Variables -> GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Mixed2Query 17 | mixed2 variables = 18 | GraphQL.Operation.withQuery 19 | """query Mixed2($withSchool: Boolean!, $withCity: Boolean!) { 20 | name 21 | school @skip(if: $withSchool) 22 | city @include(if: $withCity) 23 | }""" 24 | (Maybe.Just <| encodeMixed2Variables variables) 25 | mixed2QueryDecoder 26 | GraphQL.Errors.decoder 27 | 28 | 29 | type alias Mixed2Response = 30 | GraphQL.Response.Response GraphQL.Errors.Errors Mixed2Query 31 | 32 | 33 | type alias Mixed2Variables = 34 | { withSchool : Bool 35 | , withCity : Bool 36 | } 37 | 38 | 39 | encodeMixed2Variables : Mixed2Variables -> Json.Encode.Value 40 | encodeMixed2Variables inputs = 41 | Json.Encode.object 42 | [ ( "withSchool", Json.Encode.bool inputs.withSchool ) 43 | , ( "withCity", Json.Encode.bool inputs.withCity ) 44 | ] 45 | 46 | 47 | type alias Mixed2Query = 48 | { name : String 49 | , school : Maybe.Maybe String 50 | , city : GraphQL.Optional.Optional String 51 | } 52 | 53 | 54 | mixed2QueryDecoder : Json.Decode.Decoder Mixed2Query 55 | mixed2QueryDecoder = 56 | Json.Decode.map3 Mixed2Query 57 | (Json.Decode.field "name" Json.Decode.string) 58 | (GraphQL.Optional.nonNullFieldDecoder "school" Json.Decode.string) 59 | (GraphQL.Optional.fieldDecoder "city" Json.Decode.string) 60 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/expected-output/Union.elm: -------------------------------------------------------------------------------- 1 | module Union exposing 2 | ( Flip(..) 3 | , Heads 4 | , Tails 5 | , UnionQuery 6 | , UnionResponse 7 | , union 8 | ) 9 | 10 | import GraphQL.Errors 11 | import GraphQL.Operation 12 | import GraphQL.Response 13 | import Json.Decode 14 | 15 | 16 | union : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors UnionQuery 17 | union = 18 | GraphQL.Operation.withQuery 19 | """query Union { 20 | flip { 21 | ... on Heads { 22 | name 23 | } 24 | ... on Tails { 25 | length 26 | } 27 | } 28 | }""" 29 | Maybe.Nothing 30 | unionQueryDecoder 31 | GraphQL.Errors.decoder 32 | 33 | 34 | type alias UnionResponse = 35 | GraphQL.Response.Response GraphQL.Errors.Errors UnionQuery 36 | 37 | 38 | type alias UnionQuery = 39 | { flip : Flip 40 | } 41 | 42 | 43 | unionQueryDecoder : Json.Decode.Decoder UnionQuery 44 | unionQueryDecoder = 45 | Json.Decode.map UnionQuery 46 | (Json.Decode.field "flip" flipDecoder) 47 | 48 | 49 | type Flip 50 | = OnHeads Heads 51 | | OnTails Tails 52 | 53 | 54 | flipDecoder : Json.Decode.Decoder Flip 55 | flipDecoder = 56 | Json.Decode.oneOf 57 | [ Json.Decode.map OnHeads headsDecoder 58 | , Json.Decode.map OnTails tailsDecoder 59 | ] 60 | 61 | 62 | type alias Heads = 63 | { name : String 64 | } 65 | 66 | 67 | headsDecoder : Json.Decode.Decoder Heads 68 | headsDecoder = 69 | Json.Decode.map Heads 70 | (Json.Decode.field "name" Json.Decode.string) 71 | 72 | 73 | type alias Tails = 74 | { length : Float 75 | } 76 | 77 | 78 | tailsDecoder : Json.Decode.Decoder Tails 79 | tailsDecoder = 80 | Json.Decode.map Tails 81 | (Json.Decode.field "length" Json.Decode.float) 82 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/expected-output/SameTypeSameFieldsList.elm: -------------------------------------------------------------------------------- 1 | module SameTypeSameFieldsList exposing 2 | ( Person 3 | , Person2 4 | , Query 5 | , Response 6 | , query 7 | ) 8 | 9 | import GraphQL.Errors 10 | import GraphQL.Operation 11 | import GraphQL.Response 12 | import Json.Decode 13 | 14 | 15 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 16 | query = 17 | GraphQL.Operation.withQuery 18 | """{ 19 | me { 20 | bestFriend { 21 | age 22 | name 23 | } 24 | friends { 25 | name 26 | age 27 | } 28 | } 29 | }""" 30 | Maybe.Nothing 31 | queryDecoder 32 | GraphQL.Errors.decoder 33 | 34 | 35 | type alias Response = 36 | GraphQL.Response.Response GraphQL.Errors.Errors Query 37 | 38 | 39 | type alias Query = 40 | { me : Person 41 | } 42 | 43 | 44 | queryDecoder : Json.Decode.Decoder Query 45 | queryDecoder = 46 | Json.Decode.map Query 47 | (Json.Decode.field "me" personDecoder) 48 | 49 | 50 | type alias Person = 51 | { bestFriend : Maybe.Maybe Person2 52 | , friends : Maybe.Maybe (List (Maybe.Maybe Person2)) 53 | } 54 | 55 | 56 | personDecoder : Json.Decode.Decoder Person 57 | personDecoder = 58 | Json.Decode.map2 Person 59 | (Json.Decode.field "bestFriend" (Json.Decode.nullable person2Decoder)) 60 | (Json.Decode.field "friends" (Json.Decode.nullable (Json.Decode.list (Json.Decode.nullable person2Decoder)))) 61 | 62 | 63 | type alias Person2 = 64 | { age : Maybe.Maybe Int 65 | , name : String 66 | } 67 | 68 | 69 | person2Decoder : Json.Decode.Decoder Person2 70 | person2Decoder = 71 | Json.Decode.map2 Person2 72 | (Json.Decode.field "age" (Json.Decode.nullable Json.Decode.int)) 73 | (Json.Decode.field "name" Json.Decode.string) 74 | -------------------------------------------------------------------------------- /examples/features/src-generated/Queries/Variables.elm: -------------------------------------------------------------------------------- 1 | module Queries.Variables exposing 2 | ( TranslationQuery 3 | , TranslationResponse 4 | , TranslationVariables 5 | , translation 6 | ) 7 | 8 | import GraphQL.Enum.Language 9 | import GraphQL.Errors 10 | import GraphQL.Operation 11 | import GraphQL.Optional 12 | import GraphQL.Response 13 | import Json.Decode 14 | import Json.Encode 15 | 16 | 17 | translation : TranslationVariables -> GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors TranslationQuery 18 | translation variables = 19 | GraphQL.Operation.withQuery 20 | """query Translation($id: ID!, $language: Language) { 21 | translation(id: $id, language: $language) 22 | }""" 23 | (Maybe.Just <| encodeTranslationVariables variables) 24 | translationQueryDecoder 25 | GraphQL.Errors.decoder 26 | 27 | 28 | type alias TranslationResponse = 29 | GraphQL.Response.Response GraphQL.Errors.Errors TranslationQuery 30 | 31 | 32 | type alias TranslationVariables = 33 | { id : String 34 | , language : GraphQL.Optional.Optional GraphQL.Enum.Language.Language 35 | } 36 | 37 | 38 | encodeTranslationVariables : TranslationVariables -> Json.Encode.Value 39 | encodeTranslationVariables inputs = 40 | GraphQL.Optional.encodeObject 41 | [ ( "id", (Json.Encode.string >> GraphQL.Optional.Present) inputs.id ) 42 | , ( "language", GraphQL.Optional.map GraphQL.Enum.Language.encode inputs.language ) 43 | ] 44 | 45 | 46 | type alias TranslationQuery = 47 | { translation : Maybe.Maybe String 48 | } 49 | 50 | 51 | translationQueryDecoder : Json.Decode.Decoder TranslationQuery 52 | translationQueryDecoder = 53 | Json.Decode.map TranslationQuery 54 | (Json.Decode.field "translation" (Json.Decode.nullable Json.Decode.string)) 55 | -------------------------------------------------------------------------------- /src/GraphQL/Errors.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Errors exposing 2 | ( Errors, Error, Location, PathSegment(..) 3 | , decoder, errorDecoder, locationDecoder, pathSegmentDecoder 4 | ) 5 | 6 | {-| Types and decoder for the errors field in the GraphQL response. 7 | See . 8 | 9 | @docs Errors, Error, Location, PathSegment 10 | @docs decoder, errorDecoder, locationDecoder, pathSegmentDecoder 11 | 12 | -} 13 | 14 | import GraphQL.Optional as Optional 15 | import Json.Decode as Decode exposing (Decoder) 16 | 17 | 18 | {-| -} 19 | type alias Errors = 20 | List Error 21 | 22 | 23 | {-| -} 24 | type alias Error = 25 | { message : String 26 | , locations : Maybe (List Location) 27 | , path : Maybe (List PathSegment) 28 | } 29 | 30 | 31 | {-| -} 32 | type alias Location = 33 | { line : Int 34 | , column : Int 35 | } 36 | 37 | 38 | {-| -} 39 | type PathSegment 40 | = FieldName String 41 | | ListIndex Int 42 | 43 | 44 | {-| -} 45 | decoder : Decoder Errors 46 | decoder = 47 | Decode.list errorDecoder 48 | 49 | 50 | {-| -} 51 | errorDecoder : Decoder Error 52 | errorDecoder = 53 | Decode.map3 Error 54 | (Decode.field "message" Decode.string) 55 | (Optional.nonNullFieldDecoder "locations" <| Decode.list locationDecoder) 56 | (Optional.nonNullFieldDecoder "path" <| Decode.list pathSegmentDecoder) 57 | 58 | 59 | {-| -} 60 | locationDecoder : Decoder Location 61 | locationDecoder = 62 | Decode.map2 Location 63 | (Decode.field "line" Decode.int) 64 | (Decode.field "column" Decode.int) 65 | 66 | 67 | {-| -} 68 | pathSegmentDecoder : Decoder PathSegment 69 | pathSegmentDecoder = 70 | Decode.oneOf 71 | [ Decode.map ListIndex Decode.int 72 | , Decode.map FieldName Decode.string 73 | ] 74 | -------------------------------------------------------------------------------- /tests/gen/fixtures/directives/expected-output/Include.elm: -------------------------------------------------------------------------------- 1 | module Include exposing 2 | ( IncludeQuery 3 | , IncludeResponse 4 | , IncludeVariables 5 | , include 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Optional 11 | import GraphQL.Response 12 | import Json.Decode 13 | import Json.Encode 14 | 15 | 16 | include : IncludeVariables -> GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors IncludeQuery 17 | include variables = 18 | GraphQL.Operation.withQuery 19 | """query Include($withSchool: Boolean!, $withCity: Boolean!) { 20 | name 21 | school @include(if: $withSchool) 22 | city @include(if: $withCity) 23 | }""" 24 | (Maybe.Just <| encodeIncludeVariables variables) 25 | includeQueryDecoder 26 | GraphQL.Errors.decoder 27 | 28 | 29 | type alias IncludeResponse = 30 | GraphQL.Response.Response GraphQL.Errors.Errors IncludeQuery 31 | 32 | 33 | type alias IncludeVariables = 34 | { withSchool : Bool 35 | , withCity : Bool 36 | } 37 | 38 | 39 | encodeIncludeVariables : IncludeVariables -> Json.Encode.Value 40 | encodeIncludeVariables inputs = 41 | Json.Encode.object 42 | [ ( "withSchool", Json.Encode.bool inputs.withSchool ) 43 | , ( "withCity", Json.Encode.bool inputs.withCity ) 44 | ] 45 | 46 | 47 | type alias IncludeQuery = 48 | { name : String 49 | , school : Maybe.Maybe String 50 | , city : GraphQL.Optional.Optional String 51 | } 52 | 53 | 54 | includeQueryDecoder : Json.Decode.Decoder IncludeQuery 55 | includeQueryDecoder = 56 | Json.Decode.map3 IncludeQuery 57 | (Json.Decode.field "name" Json.Decode.string) 58 | (GraphQL.Optional.nonNullFieldDecoder "school" Json.Decode.string) 59 | (GraphQL.Optional.fieldDecoder "city" Json.Decode.string) 60 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/expected-output/InterfacePartial.elm: -------------------------------------------------------------------------------- 1 | module InterfacePartial exposing 2 | ( Animal(..) 3 | , Dog 4 | , InterfacePartialQuery 5 | , InterfacePartialResponse 6 | , interfacePartial 7 | ) 8 | 9 | import GraphQL.Errors 10 | import GraphQL.Helpers.Decode 11 | import GraphQL.Operation 12 | import GraphQL.Response 13 | import Json.Decode 14 | 15 | 16 | interfacePartial : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors InterfacePartialQuery 17 | interfacePartial = 18 | GraphQL.Operation.withQuery 19 | """query InterfacePartial { 20 | animal { 21 | ... on Dog { 22 | color 23 | hairy 24 | } 25 | } 26 | }""" 27 | Maybe.Nothing 28 | interfacePartialQueryDecoder 29 | GraphQL.Errors.decoder 30 | 31 | 32 | type alias InterfacePartialResponse = 33 | GraphQL.Response.Response GraphQL.Errors.Errors InterfacePartialQuery 34 | 35 | 36 | type alias InterfacePartialQuery = 37 | { animal : Animal 38 | } 39 | 40 | 41 | interfacePartialQueryDecoder : Json.Decode.Decoder InterfacePartialQuery 42 | interfacePartialQueryDecoder = 43 | Json.Decode.map InterfacePartialQuery 44 | (Json.Decode.field "animal" animalDecoder) 45 | 46 | 47 | type Animal 48 | = OnDog Dog 49 | | OnOtherAnimal 50 | 51 | 52 | animalDecoder : Json.Decode.Decoder Animal 53 | animalDecoder = 54 | Json.Decode.oneOf 55 | [ Json.Decode.map OnDog dogDecoder 56 | , GraphQL.Helpers.Decode.emptyObject OnOtherAnimal 57 | ] 58 | 59 | 60 | type alias Dog = 61 | { color : String 62 | , hairy : Bool 63 | } 64 | 65 | 66 | dogDecoder : Json.Decode.Decoder Dog 67 | dogDecoder = 68 | Json.Decode.map2 Dog 69 | (Json.Decode.field "color" Json.Decode.string) 70 | (Json.Decode.field "hairy" Json.Decode.bool) 71 | -------------------------------------------------------------------------------- /examples/readme/src/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (main) 2 | 3 | import Browser exposing (Document) 4 | import GraphQL.Errors exposing (Errors) 5 | import GraphQL.Operation exposing (Operation) 6 | import GraphQL.Response exposing (Response) 7 | import Html 8 | import Http 9 | import MyQuery 10 | 11 | 12 | 13 | -- Requests 14 | 15 | 16 | postOperation : Operation any Errors data -> (Result Http.Error (Response Errors data) -> msg) -> Cmd msg 17 | postOperation operation msg = 18 | Http.post 19 | { url = "/graphql" 20 | , body = Http.jsonBody (GraphQL.Operation.encode operation) 21 | , expect = Http.expectJson msg (GraphQL.Response.decoder operation) 22 | } 23 | 24 | 25 | 26 | -- Model 27 | 28 | 29 | init : () -> ( String, Cmd Msg ) 30 | init _ = 31 | ( "", postOperation MyQuery.userName GotUserName ) 32 | 33 | 34 | 35 | -- Update 36 | 37 | 38 | type Msg 39 | = GotUserName (Result Http.Error (Response Errors MyQuery.UserNameQuery)) 40 | 41 | 42 | update : Msg -> String -> ( String, Cmd Msg ) 43 | update msg _ = 44 | case msg of 45 | GotUserName (Ok (GraphQL.Response.Data data)) -> 46 | ( "user name: " ++ data.user.name, Cmd.none ) 47 | 48 | GotUserName (Ok (GraphQL.Response.Errors _ _)) -> 49 | ( "GraphQL error", Cmd.none ) 50 | 51 | GotUserName (Err _) -> 52 | ( "Http error", Cmd.none ) 53 | 54 | 55 | 56 | -- View 57 | 58 | 59 | view : String -> Document Msg 60 | view string = 61 | { title = "readme example - graphql-to-elm" 62 | , body = 63 | [ Html.text string ] 64 | } 65 | 66 | 67 | 68 | -- Main 69 | 70 | 71 | main : Program () String Msg 72 | main = 73 | Browser.document 74 | { init = init 75 | , view = view 76 | , update = update 77 | , subscriptions = always Sub.none 78 | } 79 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/expected-output/ScalarsOptional.elm: -------------------------------------------------------------------------------- 1 | module ScalarsOptional exposing 2 | ( ScalarsOptionalQuery 3 | , ScalarsOptionalResponse 4 | , ScalarsOptionalVariables 5 | , scalarsOptional 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Optional 11 | import GraphQL.Response 12 | import Json.Decode 13 | import Json.Encode 14 | 15 | 16 | scalarsOptional : ScalarsOptionalVariables -> GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors ScalarsOptionalQuery 17 | scalarsOptional variables = 18 | GraphQL.Operation.withQuery 19 | """query ScalarsOptional($string: String, $int: Int) { 20 | scalarsOptional(string: $string, int: $int) 21 | }""" 22 | (Maybe.Just <| encodeScalarsOptionalVariables variables) 23 | scalarsOptionalQueryDecoder 24 | GraphQL.Errors.decoder 25 | 26 | 27 | type alias ScalarsOptionalResponse = 28 | GraphQL.Response.Response GraphQL.Errors.Errors ScalarsOptionalQuery 29 | 30 | 31 | type alias ScalarsOptionalVariables = 32 | { string : GraphQL.Optional.Optional String 33 | , int : GraphQL.Optional.Optional Int 34 | } 35 | 36 | 37 | encodeScalarsOptionalVariables : ScalarsOptionalVariables -> Json.Encode.Value 38 | encodeScalarsOptionalVariables inputs = 39 | GraphQL.Optional.encodeObject 40 | [ ( "string", GraphQL.Optional.map Json.Encode.string inputs.string ) 41 | , ( "int", GraphQL.Optional.map Json.Encode.int inputs.int ) 42 | ] 43 | 44 | 45 | type alias ScalarsOptionalQuery = 46 | { scalarsOptional : Maybe.Maybe String 47 | } 48 | 49 | 50 | scalarsOptionalQueryDecoder : Json.Decode.Decoder ScalarsOptionalQuery 51 | scalarsOptionalQueryDecoder = 52 | Json.Decode.map ScalarsOptionalQuery 53 | (Json.Decode.field "scalarsOptional" (Json.Decode.nullable Json.Decode.string)) 54 | -------------------------------------------------------------------------------- /src/GraphQL/Helpers/Decode.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Helpers.Decode exposing (andMap, fromResult, constantString, emptyObject) 2 | 3 | {-| Some additional functions that help with decoding JSON. 4 | 5 | @docs andMap, fromResult, constantString, emptyObject 6 | 7 | -} 8 | 9 | import Json.Decode as Decode exposing (Decoder, Error) 10 | 11 | 12 | {-| Provide a pipeline for mapping decoders. 13 | Can be used for decoding large records. 14 | -} 15 | andMap : Decoder a -> Decoder (a -> b) -> Decoder b 16 | andMap = 17 | Decode.map2 (|>) 18 | 19 | 20 | {-| Turn a decode result into a decoder. 21 | -} 22 | fromResult : Result Error a -> Decoder a 23 | fromResult result = 24 | case result of 25 | Err error -> 26 | Decode.fail (Decode.errorToString error) 27 | 28 | Ok value -> 29 | Decode.succeed value 30 | 31 | 32 | {-| Decode a constant string. 33 | -} 34 | constantString : String -> Decoder String 35 | constantString constantValue = 36 | Decode.string 37 | |> Decode.andThen 38 | (\value -> 39 | if value == constantValue then 40 | Decode.succeed value 41 | 42 | else 43 | Decode.fail <| 44 | "expected '" 45 | ++ constantValue 46 | ++ "' but got '" 47 | ++ value 48 | ++ "`" 49 | ) 50 | 51 | 52 | {-| Decode an empty object `{}`. 53 | -} 54 | emptyObject : a -> Decoder a 55 | emptyObject result = 56 | Decode.keyValuePairs Decode.value 57 | |> Decode.andThen 58 | (\pairs -> 59 | case pairs of 60 | [] -> 61 | Decode.succeed result 62 | 63 | _ -> 64 | Decode.fail "expected empty object" 65 | ) 66 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/expected-output/Nested.elm: -------------------------------------------------------------------------------- 1 | module Nested exposing 2 | ( Person 3 | , Person2 4 | , Query 5 | , Response 6 | , query 7 | ) 8 | 9 | import GraphQL.Errors 10 | import GraphQL.Operation 11 | import GraphQL.Response 12 | import Json.Decode 13 | 14 | 15 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 16 | query = 17 | GraphQL.Operation.withQuery 18 | """{ 19 | i { 20 | name 21 | age 22 | bestFriend { 23 | name 24 | age 25 | email 26 | } 27 | } 28 | }""" 29 | Maybe.Nothing 30 | queryDecoder 31 | GraphQL.Errors.decoder 32 | 33 | 34 | type alias Response = 35 | GraphQL.Response.Response GraphQL.Errors.Errors Query 36 | 37 | 38 | type alias Query = 39 | { i : Person 40 | } 41 | 42 | 43 | queryDecoder : Json.Decode.Decoder Query 44 | queryDecoder = 45 | Json.Decode.map Query 46 | (Json.Decode.field "i" personDecoder) 47 | 48 | 49 | type alias Person = 50 | { name : String 51 | , age : Maybe.Maybe Int 52 | , bestFriend : Maybe.Maybe Person2 53 | } 54 | 55 | 56 | personDecoder : Json.Decode.Decoder Person 57 | personDecoder = 58 | Json.Decode.map3 Person 59 | (Json.Decode.field "name" Json.Decode.string) 60 | (Json.Decode.field "age" (Json.Decode.nullable Json.Decode.int)) 61 | (Json.Decode.field "bestFriend" (Json.Decode.nullable person2Decoder)) 62 | 63 | 64 | type alias Person2 = 65 | { name : String 66 | , age : Maybe.Maybe Int 67 | , email : Maybe.Maybe String 68 | } 69 | 70 | 71 | person2Decoder : Json.Decode.Decoder Person2 72 | person2Decoder = 73 | Json.Decode.map3 Person2 74 | (Json.Decode.field "name" Json.Decode.string) 75 | (Json.Decode.field "age" (Json.Decode.nullable Json.Decode.int)) 76 | (Json.Decode.field "email" (Json.Decode.nullable Json.Decode.string)) 77 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/expected-output/UnionList.elm: -------------------------------------------------------------------------------- 1 | module UnionList exposing 2 | ( Flip(..) 3 | , Heads 4 | , Tails 5 | , UnionListQuery 6 | , UnionListResponse 7 | , unionList 8 | ) 9 | 10 | import GraphQL.Errors 11 | import GraphQL.Operation 12 | import GraphQL.Response 13 | import Json.Decode 14 | 15 | 16 | unionList : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors UnionListQuery 17 | unionList = 18 | GraphQL.Operation.withQuery 19 | """query UnionList { 20 | flips { 21 | ... on Heads { 22 | name 23 | } 24 | ... on Tails { 25 | length 26 | } 27 | } 28 | }""" 29 | Maybe.Nothing 30 | unionListQueryDecoder 31 | GraphQL.Errors.decoder 32 | 33 | 34 | type alias UnionListResponse = 35 | GraphQL.Response.Response GraphQL.Errors.Errors UnionListQuery 36 | 37 | 38 | type alias UnionListQuery = 39 | { flips : List Flip 40 | } 41 | 42 | 43 | unionListQueryDecoder : Json.Decode.Decoder UnionListQuery 44 | unionListQueryDecoder = 45 | Json.Decode.map UnionListQuery 46 | (Json.Decode.field "flips" (Json.Decode.list flipDecoder)) 47 | 48 | 49 | type Flip 50 | = OnHeads Heads 51 | | OnTails Tails 52 | 53 | 54 | flipDecoder : Json.Decode.Decoder Flip 55 | flipDecoder = 56 | Json.Decode.oneOf 57 | [ Json.Decode.map OnHeads headsDecoder 58 | , Json.Decode.map OnTails tailsDecoder 59 | ] 60 | 61 | 62 | type alias Heads = 63 | { name : String 64 | } 65 | 66 | 67 | headsDecoder : Json.Decode.Decoder Heads 68 | headsDecoder = 69 | Json.Decode.map Heads 70 | (Json.Decode.field "name" Json.Decode.string) 71 | 72 | 73 | type alias Tails = 74 | { length : Float 75 | } 76 | 77 | 78 | tailsDecoder : Json.Decode.Decoder Tails 79 | tailsDecoder = 80 | Json.Decode.map Tails 81 | (Json.Decode.field "length" Json.Decode.float) 82 | -------------------------------------------------------------------------------- /tests/gen/fixtures/lists/expected-output/ListOfObjects.elm: -------------------------------------------------------------------------------- 1 | module ListOfObjects exposing 2 | ( Friend 3 | , Query 4 | , Response 5 | , query 6 | ) 7 | 8 | import GraphQL.Errors 9 | import GraphQL.Operation 10 | import GraphQL.Response 11 | import Json.Decode 12 | 13 | 14 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 15 | query = 16 | GraphQL.Operation.withQuery 17 | """{ 18 | friends_friend { 19 | name 20 | } 21 | friends_friendOrNull { 22 | name 23 | } 24 | friendsOrNull_friend { 25 | name 26 | } 27 | friendsOrNull_friendOrNull { 28 | name 29 | } 30 | }""" 31 | Maybe.Nothing 32 | queryDecoder 33 | GraphQL.Errors.decoder 34 | 35 | 36 | type alias Response = 37 | GraphQL.Response.Response GraphQL.Errors.Errors Query 38 | 39 | 40 | type alias Query = 41 | { friends_friend : List Friend 42 | , friends_friendOrNull : List (Maybe.Maybe Friend) 43 | , friendsOrNull_friend : Maybe.Maybe (List Friend) 44 | , friendsOrNull_friendOrNull : Maybe.Maybe (List (Maybe.Maybe Friend)) 45 | } 46 | 47 | 48 | queryDecoder : Json.Decode.Decoder Query 49 | queryDecoder = 50 | Json.Decode.map4 Query 51 | (Json.Decode.field "friends_friend" (Json.Decode.list friendDecoder)) 52 | (Json.Decode.field "friends_friendOrNull" (Json.Decode.list (Json.Decode.nullable friendDecoder))) 53 | (Json.Decode.field "friendsOrNull_friend" (Json.Decode.nullable (Json.Decode.list friendDecoder))) 54 | (Json.Decode.field "friendsOrNull_friendOrNull" (Json.Decode.nullable (Json.Decode.list (Json.Decode.nullable friendDecoder)))) 55 | 56 | 57 | type alias Friend = 58 | { name : Maybe.Maybe String 59 | } 60 | 61 | 62 | friendDecoder : Json.Decode.Decoder Friend 63 | friendDecoder = 64 | Json.Decode.map Friend 65 | (Json.Decode.field "name" (Json.Decode.nullable Json.Decode.string)) 66 | -------------------------------------------------------------------------------- /examples/basic2/src/GraphQL/Http.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Http exposing 2 | ( get 3 | , post 4 | ) 5 | 6 | import GraphQL.Errors exposing (Errors) 7 | import GraphQL.Operation exposing (Operation, Query) 8 | import GraphQL.Response exposing (Response) 9 | import Http 10 | import Url.Builder 11 | 12 | 13 | get : Operation Query Errors a -> (Result String a -> msg) -> Cmd msg 14 | get operation msg = 15 | Http.get 16 | { url = Url.Builder.absolute [ "graphql" ] (GraphQL.Operation.queryParameters operation) 17 | , expect = Http.expectJson (mapResult >> msg) (GraphQL.Response.decoder operation) 18 | } 19 | 20 | 21 | post : Operation t Errors a -> (Result String a -> msg) -> Cmd msg 22 | post operation msg = 23 | Http.post 24 | { url = "/graphql" 25 | , body = Http.jsonBody (GraphQL.Operation.encode operation) 26 | , expect = Http.expectJson (mapResult >> msg) (GraphQL.Response.decoder operation) 27 | } 28 | 29 | 30 | mapResult : Result Http.Error (Response Errors a) -> Result String a 31 | mapResult result = 32 | case result of 33 | Err error -> 34 | case error of 35 | Http.BadUrl url -> 36 | Err ("Http bad url: " ++ url) 37 | 38 | Http.Timeout -> 39 | Err "Http timeout" 40 | 41 | Http.NetworkError -> 42 | Err "Http network error" 43 | 44 | Http.BadStatus status -> 45 | Err ("Http bad status: " ++ String.fromInt status) 46 | 47 | Http.BadBody body -> 48 | Err ("Http bad body: : " ++ body) 49 | 50 | Ok response -> 51 | case response of 52 | GraphQL.Response.Data data -> 53 | Ok data 54 | 55 | GraphQL.Response.Errors [] _ -> 56 | Err "GraphQL something went wrong" 57 | 58 | GraphQL.Response.Errors (first :: _) _ -> 59 | Err first.message 60 | -------------------------------------------------------------------------------- /tests/gen/test-browser/server.ts: -------------------------------------------------------------------------------- 1 | import * as express from "express"; 2 | import * as bodyParser from "body-parser"; 3 | import { GraphQLScalarType } from "graphql"; 4 | import { ApolloServer } from "apollo-server-express"; 5 | import { IMocks } from "@graphql-tools/mock"; 6 | import { namedQueries } from "./generated/namedQueries"; 7 | import { schemas } from "./generated/schemas"; 8 | 9 | const app = express(); 10 | 11 | const timeScalar = new GraphQLScalarType({ 12 | name: "Time", 13 | serialize: (value) => `${value}`, 14 | parseValue: (value) => 15 | typeof value === "string" ? parseInt(value, 10) : null, 16 | parseLiteral: (ast) => 17 | ast.kind == "StringValue" ? parseInt(ast.value, 10) : null, 18 | }); 19 | 20 | Object.keys(schemas).forEach(async (id) => { 21 | const setNamedQuery = (payload: any) => { 22 | if (payload.operationName && !payload.query) { 23 | payload.query = namedQueries[`${id}/${payload.operationName}`]; 24 | const split = payload.operationName.split(":"); 25 | if (split.length > 1) { 26 | payload.operationName = split[1]; 27 | } 28 | } 29 | }; 30 | 31 | const typeDefs = schemas[id]; 32 | let resolvers: { [type: string]: any } = {}; 33 | let mocks: IMocks = {}; 34 | 35 | if (typeDefs.includes("scalar Time")) { 36 | resolvers["Time"] = timeScalar; 37 | mocks["Time"] = () => Date.now(); 38 | } 39 | 40 | const server = new ApolloServer({ 41 | typeDefs, 42 | resolvers, 43 | mocks, 44 | }); 45 | 46 | const endpointURL = `/graphql/${id}`; 47 | 48 | app.use(endpointURL, bodyParser.json(), (req, _resp, next) => { 49 | if (Array.isArray(req.body)) { 50 | req.body.forEach(setNamedQuery); 51 | } else { 52 | setNamedQuery(req.body); 53 | setNamedQuery(req.query); 54 | } 55 | next(); 56 | }); 57 | 58 | await server.start(); 59 | server.applyMiddleware({ app, path: endpointURL }); 60 | }); 61 | 62 | app.use(express.static(`${__dirname}/generated`)); 63 | 64 | app.listen(3000); 65 | 66 | console.log("server started on http://localhost:3000"); 67 | -------------------------------------------------------------------------------- /examples/basic/src-generated/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /examples/basic2/src-generated/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /examples/readme/src-generated/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /examples/features/src-generated/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/expected-output/InterfacePartialShared.elm: -------------------------------------------------------------------------------- 1 | module InterfacePartialShared exposing 2 | ( Animal 3 | , Dog 4 | , InterfacePartialSharedQuery 5 | , InterfacePartialSharedResponse 6 | , OnAnimal(..) 7 | , interfacePartialShared 8 | ) 9 | 10 | import GraphQL.Errors 11 | import GraphQL.Operation 12 | import GraphQL.Response 13 | import Json.Decode 14 | 15 | 16 | interfacePartialShared : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors InterfacePartialSharedQuery 17 | interfacePartialShared = 18 | GraphQL.Operation.withQuery 19 | """query InterfacePartialShared { 20 | animal { 21 | color 22 | ... on Dog { 23 | hairy 24 | } 25 | } 26 | }""" 27 | Maybe.Nothing 28 | interfacePartialSharedQueryDecoder 29 | GraphQL.Errors.decoder 30 | 31 | 32 | type alias InterfacePartialSharedResponse = 33 | GraphQL.Response.Response GraphQL.Errors.Errors InterfacePartialSharedQuery 34 | 35 | 36 | type alias InterfacePartialSharedQuery = 37 | { animal : Animal 38 | } 39 | 40 | 41 | interfacePartialSharedQueryDecoder : Json.Decode.Decoder InterfacePartialSharedQuery 42 | interfacePartialSharedQueryDecoder = 43 | Json.Decode.map InterfacePartialSharedQuery 44 | (Json.Decode.field "animal" animalDecoder) 45 | 46 | 47 | type alias Animal = 48 | { color : String 49 | , on : OnAnimal 50 | } 51 | 52 | 53 | animalDecoder : Json.Decode.Decoder Animal 54 | animalDecoder = 55 | Json.Decode.map2 Animal 56 | (Json.Decode.field "color" Json.Decode.string) 57 | onAnimalDecoder 58 | 59 | 60 | type OnAnimal 61 | = OnDog Dog 62 | | OnOtherAnimal 63 | 64 | 65 | onAnimalDecoder : Json.Decode.Decoder OnAnimal 66 | onAnimalDecoder = 67 | Json.Decode.oneOf 68 | [ Json.Decode.map OnDog dogDecoder 69 | , Json.Decode.succeed OnOtherAnimal 70 | ] 71 | 72 | 73 | type alias Dog = 74 | { hairy : Bool 75 | } 76 | 77 | 78 | dogDecoder : Json.Decode.Decoder Dog 79 | dogDecoder = 80 | Json.Decode.map Dog 81 | (Json.Decode.field "hairy" Json.Decode.bool) 82 | -------------------------------------------------------------------------------- /tests/gen/fixtures/misc/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/aliases/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/enums/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/fragments/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/expected-output/InterfaceMultiple.elm: -------------------------------------------------------------------------------- 1 | module InterfaceMultiple exposing 2 | ( Animal(..) 3 | , Bird 4 | , InterfaceMultipleQuery 5 | , InterfaceMultipleResponse 6 | , Mammal 7 | , interfaceMultiple 8 | ) 9 | 10 | import GraphQL.Errors 11 | import GraphQL.Operation 12 | import GraphQL.Response 13 | import Json.Decode 14 | 15 | 16 | interfaceMultiple : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors InterfaceMultipleQuery 17 | interfaceMultiple = 18 | GraphQL.Operation.withQuery 19 | """query InterfaceMultiple { 20 | animal { 21 | ... on Mammal { 22 | subclass 23 | } 24 | ... on Bird { 25 | color 26 | canFly 27 | } 28 | } 29 | }""" 30 | Maybe.Nothing 31 | interfaceMultipleQueryDecoder 32 | GraphQL.Errors.decoder 33 | 34 | 35 | type alias InterfaceMultipleResponse = 36 | GraphQL.Response.Response GraphQL.Errors.Errors InterfaceMultipleQuery 37 | 38 | 39 | type alias InterfaceMultipleQuery = 40 | { animal : Animal 41 | } 42 | 43 | 44 | interfaceMultipleQueryDecoder : Json.Decode.Decoder InterfaceMultipleQuery 45 | interfaceMultipleQueryDecoder = 46 | Json.Decode.map InterfaceMultipleQuery 47 | (Json.Decode.field "animal" animalDecoder) 48 | 49 | 50 | type Animal 51 | = OnBird Bird 52 | | OnMammal Mammal 53 | 54 | 55 | animalDecoder : Json.Decode.Decoder Animal 56 | animalDecoder = 57 | Json.Decode.oneOf 58 | [ Json.Decode.map OnBird birdDecoder 59 | , Json.Decode.map OnMammal mammalDecoder 60 | ] 61 | 62 | 63 | type alias Bird = 64 | { color : String 65 | , canFly : Bool 66 | } 67 | 68 | 69 | birdDecoder : Json.Decode.Decoder Bird 70 | birdDecoder = 71 | Json.Decode.map2 Bird 72 | (Json.Decode.field "color" Json.Decode.string) 73 | (Json.Decode.field "canFly" Json.Decode.bool) 74 | 75 | 76 | type alias Mammal = 77 | { subclass : String 78 | } 79 | 80 | 81 | mammalDecoder : Json.Decode.Decoder Mammal 82 | mammalDecoder = 83 | Json.Decode.map Mammal 84 | (Json.Decode.field "subclass" Json.Decode.string) 85 | -------------------------------------------------------------------------------- /tests/gen/fixtures/keywords/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/lists/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/names/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/scalars/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/customScalars/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/directives/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/schema-string/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations-named/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/operations-named_prefixed/expected-output/GraphQL/Enum/TypeKind__.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Enum.TypeKind__ exposing 2 | ( TypeKind__(..) 3 | , decoder 4 | , encode 5 | , fromString 6 | , toString 7 | ) 8 | 9 | import Json.Decode 10 | import Json.Encode 11 | 12 | 13 | type TypeKind__ 14 | = Scalar 15 | | Object 16 | | Interface 17 | | Union 18 | | Enum 19 | | InputObject 20 | | List 21 | | NonNull 22 | 23 | 24 | encode : TypeKind__ -> Json.Encode.Value 25 | encode value = 26 | Json.Encode.string (toString value) 27 | 28 | 29 | decoder : Json.Decode.Decoder TypeKind__ 30 | decoder = 31 | Json.Decode.string 32 | |> Json.Decode.andThen 33 | (\value -> 34 | value 35 | |> fromString 36 | |> Maybe.map Json.Decode.succeed 37 | |> Maybe.withDefault 38 | (Json.Decode.fail <| "unknown TypeKind__ " ++ value) 39 | ) 40 | 41 | 42 | toString : TypeKind__ -> String 43 | toString value = 44 | case value of 45 | Scalar -> 46 | "SCALAR" 47 | 48 | Object -> 49 | "OBJECT" 50 | 51 | Interface -> 52 | "INTERFACE" 53 | 54 | Union -> 55 | "UNION" 56 | 57 | Enum -> 58 | "ENUM" 59 | 60 | InputObject -> 61 | "INPUT_OBJECT" 62 | 63 | List -> 64 | "LIST" 65 | 66 | NonNull -> 67 | "NON_NULL" 68 | 69 | 70 | fromString : String -> Maybe TypeKind__ 71 | fromString value = 72 | case value of 73 | "SCALAR" -> 74 | Just Scalar 75 | 76 | "OBJECT" -> 77 | Just Object 78 | 79 | "INTERFACE" -> 80 | Just Interface 81 | 82 | "UNION" -> 83 | Just Union 84 | 85 | "ENUM" -> 86 | Just Enum 87 | 88 | "INPUT_OBJECT" -> 89 | Just InputObject 90 | 91 | "LIST" -> 92 | Just List 93 | 94 | "NON_NULL" -> 95 | Just NonNull 96 | 97 | _ -> 98 | Nothing 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/expected-output/Inputs.elm: -------------------------------------------------------------------------------- 1 | module Inputs exposing 2 | ( Inputs 3 | , InputsQuery 4 | , InputsResponse 5 | , InputsVariables 6 | , OtherInputs 7 | , inputs 8 | ) 9 | 10 | import GraphQL.Errors 11 | import GraphQL.Operation 12 | import GraphQL.Response 13 | import Json.Decode 14 | import Json.Encode 15 | 16 | 17 | inputs : InputsVariables -> GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors InputsQuery 18 | inputs variables = 19 | GraphQL.Operation.withQuery 20 | """query Inputs($inputs: Inputs!) { 21 | inputs(inputs: $inputs) 22 | }""" 23 | (Maybe.Just <| encodeInputsVariables variables) 24 | inputsQueryDecoder 25 | GraphQL.Errors.decoder 26 | 27 | 28 | type alias InputsResponse = 29 | GraphQL.Response.Response GraphQL.Errors.Errors InputsQuery 30 | 31 | 32 | type alias InputsVariables = 33 | { inputs : Inputs 34 | } 35 | 36 | 37 | encodeInputsVariables : InputsVariables -> Json.Encode.Value 38 | encodeInputsVariables inputs2 = 39 | Json.Encode.object 40 | [ ( "inputs", encodeInputs inputs2.inputs ) 41 | ] 42 | 43 | 44 | type alias Inputs = 45 | { int : Int 46 | , float : Float 47 | , other : OtherInputs 48 | } 49 | 50 | 51 | encodeInputs : Inputs -> Json.Encode.Value 52 | encodeInputs inputs2 = 53 | Json.Encode.object 54 | [ ( "int", Json.Encode.int inputs2.int ) 55 | , ( "float", Json.Encode.float inputs2.float ) 56 | , ( "other", encodeOtherInputs inputs2.other ) 57 | ] 58 | 59 | 60 | type alias OtherInputs = 61 | { string : String 62 | } 63 | 64 | 65 | encodeOtherInputs : OtherInputs -> Json.Encode.Value 66 | encodeOtherInputs inputs2 = 67 | Json.Encode.object 68 | [ ( "string", Json.Encode.string inputs2.string ) 69 | ] 70 | 71 | 72 | type alias InputsQuery = 73 | { inputs : Maybe.Maybe String 74 | } 75 | 76 | 77 | inputsQueryDecoder : Json.Decode.Decoder InputsQuery 78 | inputsQueryDecoder = 79 | Json.Decode.map InputsQuery 80 | (Json.Decode.field "inputs" (Json.Decode.nullable Json.Decode.string)) 81 | -------------------------------------------------------------------------------- /examples/features/src/GraphQL/Http.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Http exposing 2 | ( post 3 | , postBatch 4 | ) 5 | 6 | import GraphQL.Batch exposing (Batch) 7 | import GraphQL.Errors exposing (Errors) 8 | import GraphQL.Operation exposing (Operation) 9 | import GraphQL.Response exposing (Response) 10 | import Http 11 | 12 | 13 | post : Operation t Errors a -> (Result String a -> msg) -> Cmd msg 14 | post operation msg = 15 | Http.post 16 | { url = "/graphql" 17 | , body = Http.jsonBody (GraphQL.Operation.encode operation) 18 | , expect = Http.expectJson (mapResult >> msg) (GraphQL.Response.decoder operation) 19 | } 20 | 21 | 22 | mapResult : Result Http.Error (Response Errors a) -> Result String a 23 | mapResult = 24 | Result.map GraphQL.Response.toResult >> mapBatchResult 25 | 26 | 27 | postBatch : Batch Errors a -> (Result String a -> msg) -> Cmd msg 28 | postBatch batch msg = 29 | Http.post 30 | { url = "/graphql" 31 | , body = Http.jsonBody (GraphQL.Batch.encode batch) 32 | , expect = Http.expectJson (mapBatchResult >> msg) (GraphQL.Batch.decoder batch) 33 | } 34 | 35 | 36 | mapBatchResult : Result Http.Error (Result Errors a) -> Result String a 37 | mapBatchResult httpResult = 38 | case httpResult of 39 | Err error -> 40 | Err (httpErrorToString error) 41 | 42 | Ok graphqlResult -> 43 | case graphqlResult of 44 | Err [] -> 45 | Err "GraphQL something went wrong" 46 | 47 | Err (head :: _) -> 48 | Err head.message 49 | 50 | Ok data -> 51 | Ok data 52 | 53 | 54 | httpErrorToString : Http.Error -> String 55 | httpErrorToString error = 56 | case error of 57 | Http.BadUrl url -> 58 | "Http bad url: " ++ url 59 | 60 | Http.Timeout -> 61 | "Http timeout" 62 | 63 | Http.NetworkError -> 64 | "Http network error" 65 | 66 | Http.BadStatus status -> 67 | "Http bad status: " ++ String.fromInt status 68 | 69 | Http.BadBody body -> 70 | "Http bad body: : " ++ body 71 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/expected-output/OtherTypeOtherFields.elm: -------------------------------------------------------------------------------- 1 | module OtherTypeOtherFields exposing 2 | ( Dog 3 | , Person 4 | , Person2 5 | , Person22 6 | , Query 7 | , Response 8 | , query 9 | ) 10 | 11 | import GraphQL.Errors 12 | import GraphQL.Operation 13 | import GraphQL.Response 14 | import Json.Decode 15 | 16 | 17 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 18 | query = 19 | GraphQL.Operation.withQuery 20 | """{ 21 | i { 22 | dog { 23 | name 24 | } 25 | } 26 | me { 27 | name 28 | } 29 | you { 30 | email 31 | } 32 | }""" 33 | Maybe.Nothing 34 | queryDecoder 35 | GraphQL.Errors.decoder 36 | 37 | 38 | type alias Response = 39 | GraphQL.Response.Response GraphQL.Errors.Errors Query 40 | 41 | 42 | type alias Query = 43 | { i : Person 44 | , me : Person2 45 | , you : Person22 46 | } 47 | 48 | 49 | queryDecoder : Json.Decode.Decoder Query 50 | queryDecoder = 51 | Json.Decode.map3 Query 52 | (Json.Decode.field "i" personDecoder) 53 | (Json.Decode.field "me" person2Decoder) 54 | (Json.Decode.field "you" person22Decoder) 55 | 56 | 57 | type alias Person = 58 | { dog : Maybe.Maybe Dog 59 | } 60 | 61 | 62 | personDecoder : Json.Decode.Decoder Person 63 | personDecoder = 64 | Json.Decode.map Person 65 | (Json.Decode.field "dog" (Json.Decode.nullable dogDecoder)) 66 | 67 | 68 | type alias Dog = 69 | { name : Maybe.Maybe String 70 | } 71 | 72 | 73 | dogDecoder : Json.Decode.Decoder Dog 74 | dogDecoder = 75 | Json.Decode.map Dog 76 | (Json.Decode.field "name" (Json.Decode.nullable Json.Decode.string)) 77 | 78 | 79 | type alias Person2 = 80 | { name : String 81 | } 82 | 83 | 84 | person2Decoder : Json.Decode.Decoder Person2 85 | person2Decoder = 86 | Json.Decode.map Person2 87 | (Json.Decode.field "name" Json.Decode.string) 88 | 89 | 90 | type alias Person22 = 91 | { email : Maybe.Maybe String 92 | } 93 | 94 | 95 | person22Decoder : Json.Decode.Decoder Person22 96 | person22Decoder = 97 | Json.Decode.map Person22 98 | (Json.Decode.field "email" (Json.Decode.nullable Json.Decode.string)) 99 | -------------------------------------------------------------------------------- /src/GraphQL/Response.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Response exposing (Response(..), mapData, mapErrors, toResult, decoder) 2 | 3 | {-| The GraphQL response type. 4 | See . 5 | 6 | @docs Response, mapData, mapErrors, toResult, decoder 7 | 8 | -} 9 | 10 | import GraphQL.Operation as Operation exposing (Operation) 11 | import GraphQL.Optional as Optional exposing (Optional(..)) 12 | import Json.Decode as Decode exposing (Decoder) 13 | 14 | 15 | {-| -} 16 | type Response e a 17 | = Data a 18 | | Errors e (Optional a) 19 | 20 | 21 | {-| Converts the data type of the response. 22 | -} 23 | mapData : (a -> b) -> Response e a -> Response e b 24 | mapData mapper response = 25 | case response of 26 | Data data -> 27 | Data (mapper data) 28 | 29 | Errors errors optionalData -> 30 | Errors errors <| 31 | case optionalData of 32 | Absent -> 33 | Absent 34 | 35 | Null -> 36 | Null 37 | 38 | Present data -> 39 | Present (mapper data) 40 | 41 | 42 | {-| Converts the errors type of the response. 43 | -} 44 | mapErrors : (e1 -> e2) -> Response e1 a -> Response e2 a 45 | mapErrors mapper response = 46 | case response of 47 | Data data -> 48 | Data data 49 | 50 | Errors errors data -> 51 | Errors (mapper errors) data 52 | 53 | 54 | {-| Converts a `Response` to a `Result`. 55 | Note that the optional data in the `Errors` case will be lost. 56 | -} 57 | toResult : Response e a -> Result e a 58 | toResult response = 59 | case response of 60 | Data data -> 61 | Ok data 62 | 63 | Errors errors _ -> 64 | Err errors 65 | 66 | 67 | {-| Decoder for the response of an operation. 68 | -} 69 | decoder : Operation t e a -> Decoder (Response e a) 70 | decoder operation = 71 | Decode.oneOf 72 | [ Decode.map2 Errors 73 | (Decode.field "errors" <| Operation.errorsDecoder operation) 74 | (Optional.fieldDecoder "data" <| Operation.dataDecoder operation) 75 | , Decode.map Data 76 | (Decode.field "data" <| Operation.dataDecoder operation) 77 | ] 78 | -------------------------------------------------------------------------------- /tests/gen/fixtures/aliases/expected-output/Query.elm: -------------------------------------------------------------------------------- 1 | module Query exposing 2 | ( AliasesQuery 3 | , AliasesResponse 4 | , User 5 | , User2 6 | , aliases 7 | ) 8 | 9 | import GraphQL.Errors 10 | import GraphQL.Operation 11 | import GraphQL.Response 12 | import Json.Decode 13 | 14 | 15 | aliases : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors AliasesQuery 16 | aliases = 17 | GraphQL.Operation.withQuery 18 | """query Aliases { 19 | user1: user { 20 | id 21 | email 22 | } 23 | user2: user { 24 | id 25 | name 26 | } 27 | user3: user { 28 | id 29 | email 30 | } 31 | user4: userOrNull { 32 | id 33 | name 34 | } 35 | user { 36 | id 37 | email 38 | } 39 | userOrNull { 40 | id 41 | name 42 | } 43 | }""" 44 | Maybe.Nothing 45 | aliasesQueryDecoder 46 | GraphQL.Errors.decoder 47 | 48 | 49 | type alias AliasesResponse = 50 | GraphQL.Response.Response GraphQL.Errors.Errors AliasesQuery 51 | 52 | 53 | type alias AliasesQuery = 54 | { user1 : User 55 | , user2 : User2 56 | , user3 : User 57 | , user4 : Maybe.Maybe User2 58 | , user : User 59 | , userOrNull : Maybe.Maybe User2 60 | } 61 | 62 | 63 | aliasesQueryDecoder : Json.Decode.Decoder AliasesQuery 64 | aliasesQueryDecoder = 65 | Json.Decode.map6 AliasesQuery 66 | (Json.Decode.field "user1" userDecoder) 67 | (Json.Decode.field "user2" user2Decoder) 68 | (Json.Decode.field "user3" userDecoder) 69 | (Json.Decode.field "user4" (Json.Decode.nullable user2Decoder)) 70 | (Json.Decode.field "user" userDecoder) 71 | (Json.Decode.field "userOrNull" (Json.Decode.nullable user2Decoder)) 72 | 73 | 74 | type alias User = 75 | { id : String 76 | , email : String 77 | } 78 | 79 | 80 | userDecoder : Json.Decode.Decoder User 81 | userDecoder = 82 | Json.Decode.map2 User 83 | (Json.Decode.field "id" Json.Decode.string) 84 | (Json.Decode.field "email" Json.Decode.string) 85 | 86 | 87 | type alias User2 = 88 | { id : String 89 | , name : String 90 | } 91 | 92 | 93 | user2Decoder : Json.Decode.Decoder User2 94 | user2Decoder = 95 | Json.Decode.map2 User2 96 | (Json.Decode.field "id" Json.Decode.string) 97 | (Json.Decode.field "name" Json.Decode.string) 98 | -------------------------------------------------------------------------------- /tests/gen/test-browser/src/GraphQL/Http.elm: -------------------------------------------------------------------------------- 1 | module GraphQL.Http exposing 2 | ( getQuery 3 | , postBatch 4 | , postMutation 5 | , postPlainBatch 6 | , postQuery 7 | ) 8 | 9 | import GraphQL.Batch as Batch 10 | import GraphQL.Operation as Operation exposing (Mutation, Operation, Query) 11 | import GraphQL.PlainBatch as PlainBatch 12 | import GraphQL.Response as Response exposing (Response) 13 | import Http 14 | import Url.Builder 15 | 16 | 17 | getQuery : String -> Operation Query e a -> (Result Http.Error (Response e a) -> msg) -> Cmd msg 18 | getQuery baseUrl operation msg = 19 | Http.get 20 | { url = getQueryUrl baseUrl operation 21 | , expect = expectOperationResponse msg operation 22 | } 23 | 24 | 25 | getQueryUrl : String -> Operation Query e a -> String 26 | getQueryUrl baseUrl operation = 27 | baseUrl ++ Url.Builder.toQuery (Operation.queryParameters operation) 28 | 29 | 30 | postQuery : String -> Operation Query e a -> (Result Http.Error (Response e a) -> msg) -> Cmd msg 31 | postQuery = 32 | postOperation 33 | 34 | 35 | postMutation : String -> Operation Mutation e a -> (Result Http.Error (Response e a) -> msg) -> Cmd msg 36 | postMutation = 37 | postOperation 38 | 39 | 40 | postOperation : String -> Operation t e a -> (Result Http.Error (Response e a) -> msg) -> Cmd msg 41 | postOperation url operation msg = 42 | Http.post 43 | { url = url 44 | , body = Http.jsonBody (Operation.encode operation) 45 | , expect = expectOperationResponse msg operation 46 | } 47 | 48 | 49 | expectOperationResponse : (Result Http.Error (Response e a) -> msg) -> Operation t e a -> Http.Expect msg 50 | expectOperationResponse msg operation = 51 | Http.expectJson msg (Response.decoder operation) 52 | 53 | 54 | postBatch : String -> Batch.Batch e a -> (Result Http.Error (Result e a) -> msg) -> Cmd msg 55 | postBatch url batch msg = 56 | Http.post 57 | { url = url 58 | , body = Http.jsonBody (Batch.encode batch) 59 | , expect = Http.expectJson msg (Batch.decoder batch) 60 | } 61 | 62 | 63 | postPlainBatch : String -> PlainBatch.Batch a -> (Result Http.Error a -> msg) -> Cmd msg 64 | postPlainBatch url batch msg = 65 | Http.post 66 | { url = url 67 | , body = Http.jsonBody (PlainBatch.encode batch) 68 | , expect = Http.expectJson msg (PlainBatch.decoder batch) 69 | } 70 | -------------------------------------------------------------------------------- /examples/features/src-generated/Queries/Fragments.elm: -------------------------------------------------------------------------------- 1 | module Queries.Fragments exposing 2 | ( Message 3 | , Query 4 | , Response 5 | , User 6 | , query 7 | ) 8 | 9 | import GraphQL.Errors 10 | import GraphQL.Operation 11 | import GraphQL.Response 12 | import Json.Decode 13 | 14 | 15 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 16 | query = 17 | GraphQL.Operation.withQuery 18 | ("""query { 19 | user { 20 | ...userFields 21 | } 22 | lastMessage { 23 | ...messageFields 24 | } 25 | messages { 26 | ...messageFields 27 | } 28 | }""" 29 | ++ userFields 30 | ++ messageFields 31 | ) 32 | Maybe.Nothing 33 | queryDecoder 34 | GraphQL.Errors.decoder 35 | 36 | 37 | userFields : String 38 | userFields = 39 | """fragment userFields on User { 40 | id 41 | name 42 | email 43 | }""" 44 | 45 | 46 | messageFields : String 47 | messageFields = 48 | """fragment messageFields on Message { 49 | id 50 | from { 51 | ...userFields 52 | } 53 | message 54 | }""" 55 | 56 | 57 | type alias Response = 58 | GraphQL.Response.Response GraphQL.Errors.Errors Query 59 | 60 | 61 | type alias Query = 62 | { user : User 63 | , lastMessage : Maybe.Maybe Message 64 | , messages : List Message 65 | } 66 | 67 | 68 | queryDecoder : Json.Decode.Decoder Query 69 | queryDecoder = 70 | Json.Decode.map3 Query 71 | (Json.Decode.field "user" userDecoder) 72 | (Json.Decode.field "lastMessage" (Json.Decode.nullable messageDecoder)) 73 | (Json.Decode.field "messages" (Json.Decode.list messageDecoder)) 74 | 75 | 76 | type alias User = 77 | { id : String 78 | , name : String 79 | , email : String 80 | } 81 | 82 | 83 | userDecoder : Json.Decode.Decoder User 84 | userDecoder = 85 | Json.Decode.map3 User 86 | (Json.Decode.field "id" Json.Decode.string) 87 | (Json.Decode.field "name" Json.Decode.string) 88 | (Json.Decode.field "email" Json.Decode.string) 89 | 90 | 91 | type alias Message = 92 | { id : String 93 | , from : User 94 | , message : String 95 | } 96 | 97 | 98 | messageDecoder : Json.Decode.Decoder Message 99 | messageDecoder = 100 | Json.Decode.map3 Message 101 | (Json.Decode.field "id" Json.Decode.string) 102 | (Json.Decode.field "from" userDecoder) 103 | (Json.Decode.field "message" Json.Decode.string) 104 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/expected-output/UnionPartial.elm: -------------------------------------------------------------------------------- 1 | module UnionPartial exposing 2 | ( Flip(..) 3 | , Flip2(..) 4 | , Heads 5 | , Tails 6 | , UnionPartialQuery 7 | , UnionPartialResponse 8 | , unionPartial 9 | ) 10 | 11 | import GraphQL.Errors 12 | import GraphQL.Helpers.Decode 13 | import GraphQL.Operation 14 | import GraphQL.Response 15 | import Json.Decode 16 | 17 | 18 | unionPartial : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors UnionPartialQuery 19 | unionPartial = 20 | GraphQL.Operation.withQuery 21 | """query UnionPartial { 22 | flip { 23 | ... on Heads { 24 | name 25 | } 26 | } 27 | flipOrNull { 28 | ... on Tails { 29 | length 30 | } 31 | } 32 | }""" 33 | Maybe.Nothing 34 | unionPartialQueryDecoder 35 | GraphQL.Errors.decoder 36 | 37 | 38 | type alias UnionPartialResponse = 39 | GraphQL.Response.Response GraphQL.Errors.Errors UnionPartialQuery 40 | 41 | 42 | type alias UnionPartialQuery = 43 | { flip : Flip 44 | , flipOrNull : Maybe.Maybe Flip2 45 | } 46 | 47 | 48 | unionPartialQueryDecoder : Json.Decode.Decoder UnionPartialQuery 49 | unionPartialQueryDecoder = 50 | Json.Decode.map2 UnionPartialQuery 51 | (Json.Decode.field "flip" flipDecoder) 52 | (Json.Decode.field "flipOrNull" (Json.Decode.nullable flip2Decoder)) 53 | 54 | 55 | type Flip 56 | = OnHeads Heads 57 | | OnOtherFlip 58 | 59 | 60 | flipDecoder : Json.Decode.Decoder Flip 61 | flipDecoder = 62 | Json.Decode.oneOf 63 | [ Json.Decode.map OnHeads headsDecoder 64 | , GraphQL.Helpers.Decode.emptyObject OnOtherFlip 65 | ] 66 | 67 | 68 | type alias Heads = 69 | { name : String 70 | } 71 | 72 | 73 | headsDecoder : Json.Decode.Decoder Heads 74 | headsDecoder = 75 | Json.Decode.map Heads 76 | (Json.Decode.field "name" Json.Decode.string) 77 | 78 | 79 | type Flip2 80 | = OnTails Tails 81 | | OnOtherFlip2 82 | 83 | 84 | flip2Decoder : Json.Decode.Decoder Flip2 85 | flip2Decoder = 86 | Json.Decode.oneOf 87 | [ Json.Decode.map OnTails tailsDecoder 88 | , GraphQL.Helpers.Decode.emptyObject OnOtherFlip2 89 | ] 90 | 91 | 92 | type alias Tails = 93 | { length : Float 94 | } 95 | 96 | 97 | tailsDecoder : Json.Decode.Decoder Tails 98 | tailsDecoder = 99 | Json.Decode.map Tails 100 | (Json.Decode.field "length" Json.Decode.float) 101 | -------------------------------------------------------------------------------- /tests/gen/fixtures/objects/expected-output/Recursive.elm: -------------------------------------------------------------------------------- 1 | module Recursive exposing 2 | ( Comment 3 | , Comment2 4 | , Comment3 5 | , Comment4 6 | , Query 7 | , Response 8 | , query 9 | ) 10 | 11 | import GraphQL.Errors 12 | import GraphQL.Operation 13 | import GraphQL.Response 14 | import Json.Decode 15 | 16 | 17 | query : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors Query 18 | query = 19 | GraphQL.Operation.withQuery 20 | """{ 21 | comments { 22 | message 23 | responses { 24 | message 25 | responses { 26 | message 27 | responses { 28 | message 29 | } 30 | } 31 | } 32 | } 33 | }""" 34 | Maybe.Nothing 35 | queryDecoder 36 | GraphQL.Errors.decoder 37 | 38 | 39 | type alias Response = 40 | GraphQL.Response.Response GraphQL.Errors.Errors Query 41 | 42 | 43 | type alias Query = 44 | { comments : List Comment4 45 | } 46 | 47 | 48 | queryDecoder : Json.Decode.Decoder Query 49 | queryDecoder = 50 | Json.Decode.map Query 51 | (Json.Decode.field "comments" (Json.Decode.list comment4Decoder)) 52 | 53 | 54 | type alias Comment4 = 55 | { message : String 56 | , responses : List Comment3 57 | } 58 | 59 | 60 | comment4Decoder : Json.Decode.Decoder Comment4 61 | comment4Decoder = 62 | Json.Decode.map2 Comment4 63 | (Json.Decode.field "message" Json.Decode.string) 64 | (Json.Decode.field "responses" (Json.Decode.list comment3Decoder)) 65 | 66 | 67 | type alias Comment3 = 68 | { message : String 69 | , responses : List Comment2 70 | } 71 | 72 | 73 | comment3Decoder : Json.Decode.Decoder Comment3 74 | comment3Decoder = 75 | Json.Decode.map2 Comment3 76 | (Json.Decode.field "message" Json.Decode.string) 77 | (Json.Decode.field "responses" (Json.Decode.list comment2Decoder)) 78 | 79 | 80 | type alias Comment2 = 81 | { message : String 82 | , responses : List Comment 83 | } 84 | 85 | 86 | comment2Decoder : Json.Decode.Decoder Comment2 87 | comment2Decoder = 88 | Json.Decode.map2 Comment2 89 | (Json.Decode.field "message" Json.Decode.string) 90 | (Json.Decode.field "responses" (Json.Decode.list commentDecoder)) 91 | 92 | 93 | type alias Comment = 94 | { message : String 95 | } 96 | 97 | 98 | commentDecoder : Json.Decode.Decoder Comment 99 | commentDecoder = 100 | Json.Decode.map Comment 101 | (Json.Decode.field "message" Json.Decode.string) 102 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/expected-output/FragmentInFragmentPartial.elm: -------------------------------------------------------------------------------- 1 | module FragmentInFragmentPartial exposing 2 | ( Animal 3 | , Dog 4 | , FragmentInFragmentPartialQuery 5 | , FragmentInFragmentPartialResponse 6 | , Mammal(..) 7 | , OnAnimal(..) 8 | , fragmentInFragmentPartial 9 | ) 10 | 11 | import GraphQL.Errors 12 | import GraphQL.Helpers.Decode 13 | import GraphQL.Operation 14 | import GraphQL.Response 15 | import Json.Decode 16 | 17 | 18 | fragmentInFragmentPartial : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors FragmentInFragmentPartialQuery 19 | fragmentInFragmentPartial = 20 | GraphQL.Operation.withQuery 21 | """query FragmentInFragmentPartial { 22 | animal { 23 | color 24 | ... on Mammal { 25 | ... on Dog { 26 | hairy 27 | } 28 | } 29 | } 30 | }""" 31 | Maybe.Nothing 32 | fragmentInFragmentPartialQueryDecoder 33 | GraphQL.Errors.decoder 34 | 35 | 36 | type alias FragmentInFragmentPartialResponse = 37 | GraphQL.Response.Response GraphQL.Errors.Errors FragmentInFragmentPartialQuery 38 | 39 | 40 | type alias FragmentInFragmentPartialQuery = 41 | { animal : Animal 42 | } 43 | 44 | 45 | fragmentInFragmentPartialQueryDecoder : Json.Decode.Decoder FragmentInFragmentPartialQuery 46 | fragmentInFragmentPartialQueryDecoder = 47 | Json.Decode.map FragmentInFragmentPartialQuery 48 | (Json.Decode.field "animal" animalDecoder) 49 | 50 | 51 | type alias Animal = 52 | { color : String 53 | , on : OnAnimal 54 | } 55 | 56 | 57 | animalDecoder : Json.Decode.Decoder Animal 58 | animalDecoder = 59 | Json.Decode.map2 Animal 60 | (Json.Decode.field "color" Json.Decode.string) 61 | onAnimalDecoder 62 | 63 | 64 | type OnAnimal 65 | = OnMammal Mammal 66 | | OnOtherAnimal 67 | 68 | 69 | onAnimalDecoder : Json.Decode.Decoder OnAnimal 70 | onAnimalDecoder = 71 | Json.Decode.oneOf 72 | [ Json.Decode.map OnMammal mammalDecoder 73 | , Json.Decode.succeed OnOtherAnimal 74 | ] 75 | 76 | 77 | type Mammal 78 | = OnDog Dog 79 | | OnOtherMammal 80 | 81 | 82 | mammalDecoder : Json.Decode.Decoder Mammal 83 | mammalDecoder = 84 | Json.Decode.oneOf 85 | [ Json.Decode.map OnDog dogDecoder 86 | , GraphQL.Helpers.Decode.emptyObject OnOtherMammal 87 | ] 88 | 89 | 90 | type alias Dog = 91 | { hairy : Bool 92 | } 93 | 94 | 95 | dogDecoder : Json.Decode.Decoder Dog 96 | dogDecoder = 97 | Json.Decode.map Dog 98 | (Json.Decode.field "hairy" Json.Decode.bool) 99 | -------------------------------------------------------------------------------- /tests/gen/fixtures/variables/expected-output/InputsMultiple.elm: -------------------------------------------------------------------------------- 1 | module InputsMultiple exposing 2 | ( Inputs 3 | , InputsMultipleQuery 4 | , InputsMultipleResponse 5 | , InputsMultipleVariables 6 | , OtherInputs 7 | , inputsMultiple 8 | ) 9 | 10 | import GraphQL.Errors 11 | import GraphQL.Operation 12 | import GraphQL.Optional 13 | import GraphQL.Response 14 | import Json.Decode 15 | import Json.Encode 16 | 17 | 18 | inputsMultiple : InputsMultipleVariables -> GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors InputsMultipleQuery 19 | inputsMultiple variables = 20 | GraphQL.Operation.withQuery 21 | """query InputsMultiple($inputs: Inputs!, $inputs2: Inputs) { 22 | inputsMultiple(inputs: $inputs, inputs2: $inputs2) 23 | }""" 24 | (Maybe.Just <| encodeInputsMultipleVariables variables) 25 | inputsMultipleQueryDecoder 26 | GraphQL.Errors.decoder 27 | 28 | 29 | type alias InputsMultipleResponse = 30 | GraphQL.Response.Response GraphQL.Errors.Errors InputsMultipleQuery 31 | 32 | 33 | type alias InputsMultipleVariables = 34 | { inputs : Inputs 35 | , inputs2 : GraphQL.Optional.Optional Inputs 36 | } 37 | 38 | 39 | encodeInputsMultipleVariables : InputsMultipleVariables -> Json.Encode.Value 40 | encodeInputsMultipleVariables inputs = 41 | GraphQL.Optional.encodeObject 42 | [ ( "inputs", (encodeInputs >> GraphQL.Optional.Present) inputs.inputs ) 43 | , ( "inputs2", GraphQL.Optional.map encodeInputs inputs.inputs2 ) 44 | ] 45 | 46 | 47 | type alias Inputs = 48 | { int : Int 49 | , float : Float 50 | , other : OtherInputs 51 | } 52 | 53 | 54 | encodeInputs : Inputs -> Json.Encode.Value 55 | encodeInputs inputs = 56 | Json.Encode.object 57 | [ ( "int", Json.Encode.int inputs.int ) 58 | , ( "float", Json.Encode.float inputs.float ) 59 | , ( "other", encodeOtherInputs inputs.other ) 60 | ] 61 | 62 | 63 | type alias OtherInputs = 64 | { string : String 65 | } 66 | 67 | 68 | encodeOtherInputs : OtherInputs -> Json.Encode.Value 69 | encodeOtherInputs inputs = 70 | Json.Encode.object 71 | [ ( "string", Json.Encode.string inputs.string ) 72 | ] 73 | 74 | 75 | type alias InputsMultipleQuery = 76 | { inputsMultiple : Maybe.Maybe String 77 | } 78 | 79 | 80 | inputsMultipleQueryDecoder : Json.Decode.Decoder InputsMultipleQuery 81 | inputsMultipleQueryDecoder = 82 | Json.Decode.map InputsMultipleQuery 83 | (Json.Decode.field "inputsMultiple" (Json.Decode.nullable Json.Decode.string)) 84 | -------------------------------------------------------------------------------- /tests/gen/fixtures/inline-fragments/expected-output/Interface.elm: -------------------------------------------------------------------------------- 1 | module Interface exposing 2 | ( Animal(..) 3 | , Bird 4 | , Dog 5 | , Dolphin 6 | , InterfaceQuery 7 | , InterfaceResponse 8 | , interface 9 | ) 10 | 11 | import GraphQL.Errors 12 | import GraphQL.Operation 13 | import GraphQL.Response 14 | import Json.Decode 15 | 16 | 17 | interface : GraphQL.Operation.Operation GraphQL.Operation.Query GraphQL.Errors.Errors InterfaceQuery 18 | interface = 19 | GraphQL.Operation.withQuery 20 | """query Interface { 21 | animal { 22 | ... on Dog { 23 | color 24 | hairy 25 | } 26 | ... on Dolphin { 27 | color 28 | fins 29 | } 30 | ... on Bird { 31 | color 32 | canFly 33 | } 34 | } 35 | }""" 36 | Maybe.Nothing 37 | interfaceQueryDecoder 38 | GraphQL.Errors.decoder 39 | 40 | 41 | type alias InterfaceResponse = 42 | GraphQL.Response.Response GraphQL.Errors.Errors InterfaceQuery 43 | 44 | 45 | type alias InterfaceQuery = 46 | { animal : Animal 47 | } 48 | 49 | 50 | interfaceQueryDecoder : Json.Decode.Decoder InterfaceQuery 51 | interfaceQueryDecoder = 52 | Json.Decode.map InterfaceQuery 53 | (Json.Decode.field "animal" animalDecoder) 54 | 55 | 56 | type Animal 57 | = OnDog Dog 58 | | OnDolphin Dolphin 59 | | OnBird Bird 60 | 61 | 62 | animalDecoder : Json.Decode.Decoder Animal 63 | animalDecoder = 64 | Json.Decode.oneOf 65 | [ Json.Decode.map OnDog dogDecoder 66 | , Json.Decode.map OnDolphin dolphinDecoder 67 | , Json.Decode.map OnBird birdDecoder 68 | ] 69 | 70 | 71 | type alias Dog = 72 | { color : String 73 | , hairy : Bool 74 | } 75 | 76 | 77 | dogDecoder : Json.Decode.Decoder Dog 78 | dogDecoder = 79 | Json.Decode.map2 Dog 80 | (Json.Decode.field "color" Json.Decode.string) 81 | (Json.Decode.field "hairy" Json.Decode.bool) 82 | 83 | 84 | type alias Dolphin = 85 | { color : String 86 | , fins : Int 87 | } 88 | 89 | 90 | dolphinDecoder : Json.Decode.Decoder Dolphin 91 | dolphinDecoder = 92 | Json.Decode.map2 Dolphin 93 | (Json.Decode.field "color" Json.Decode.string) 94 | (Json.Decode.field "fins" Json.Decode.int) 95 | 96 | 97 | type alias Bird = 98 | { color : String 99 | , canFly : Bool 100 | } 101 | 102 | 103 | birdDecoder : Json.Decode.Decoder Bird 104 | birdDecoder = 105 | Json.Decode.map2 Bird 106 | (Json.Decode.field "color" Json.Decode.string) 107 | (Json.Decode.field "canFly" Json.Decode.bool) 108 | --------------------------------------------------------------------------------