spec/graphql/language/generation_spec.rb in graphql-0.19.3 vs spec/graphql/language/generation_spec.rb in graphql-0.19.4

- old
+ new

@@ -39,77 +39,161 @@ assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string end end describe "schema" do - # From: https://github.com/graphql/graphql-js/blob/a725499b155285c2e33647a93393c82689b20b0f/src/language/__tests__/schema-kitchen-sink.graphql - let(:query_string) {<<-schema - schema { - query: QueryType - mutation: MutationType + describe "schema with convention names for root types" do + let(:query_string) {<<-schema + schema { + query: Query + mutation: Mutation + subscription: Subscription + } + schema } - type Foo implements Bar { - one: Type - two(argument: InputType!): Type - three(argument: InputType, other: String): Int - four(argument: String = "string"): String - five(argument: [String] = ["string", "string"]): String - six(argument: InputType = {key: "value"}): Type - } + it 'omits schema definition' do + refute document.to_query_string =~ /schema/ + end + end - type AnnotatedObject @onObject(arg: "value") { - annotatedField(arg: Type = "default" @onArg): Type @onField + describe "schema with custom query root name" do + let(:query_string) {<<-schema + schema { + query: MyQuery + mutation: Mutation + subscription: Subscription + } + schema } - interface Bar { - one: Type - four(argument: String = "string"): String + it 'includes schema definition' do + assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string + end + end + + describe "schema with custom mutation root name" do + let(:query_string) {<<-schema + schema { + query: Query + mutation: MyMutation + subscription: Subscription + } + schema } - interface AnnotatedInterface @onInterface { - annotatedField(arg: Type @onArg): Type @onField + it 'includes schema definition' do + assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string + end + end + + describe "schema with custom subscription root name" do + let(:query_string) {<<-schema + schema { + query: Query + mutation: Mutation + subscription: MySubscription + } + schema } - union Feed = Story | Article | Advert + it 'includes schema definition' do + assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string + end + end - union AnnotatedUnion @onUnion = A | B + describe "full featured schema" do + # From: https://github.com/graphql/graphql-js/blob/a725499b155285c2e33647a93393c82689b20b0f/src/language/__tests__/schema-kitchen-sink.graphql + let(:query_string) {<<-schema + schema { + query: QueryType + mutation: MutationType + } - scalar CustomScalar + # Union description + union AnnotatedUnion @onUnion = A | B - scalar AnnotatedScalar @onScalar + type Foo implements Bar { + one: Type + two(argument: InputType!): Type + three(argument: InputType, other: String): Int + four(argument: String = "string"): String + five(argument: [String] = ["string", "string"]): String + six(argument: InputType = {key: "value"}): Type + } - enum Site { - DESKTOP - MOBILE - } + # Scalar description + scalar CustomScalar - enum AnnotatedEnum @onEnum { - ANNOTATED_VALUE @onEnumValue - OTHER_VALUE - } + type AnnotatedObject @onObject(arg: "value") { + annotatedField(arg: Type = "default" @onArg): Type @onField + } - input InputType { - key: String! - answer: Int = 42 - } + interface Bar { + one: Type + four(argument: String = "string"): String + } - input AnnotatedInput @onInputObjectType { - annotatedField: Type @onField - } + # Enum description + enum Site { + # Enum value description + DESKTOP + MOBILE + } - directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT + interface AnnotatedInterface @onInterface { + annotatedField(arg: Type @onArg): Type @onField + } - directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT - schema - } + union Feed = Story | Article | Advert - it "generate" do - assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string - end + # Input description + input InputType { + key: String! + answer: Int = 42 + } - it "doesn't mutate the document" do - assert_equal document.to_query_string, document.to_query_string + union AnnotatedUnion @onUnion = A | B + + scalar CustomScalar + + # Directive description + directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT + + scalar AnnotatedScalar @onScalar + + enum Site { + DESKTOP + MOBILE + } + + enum AnnotatedEnum @onEnum { + ANNOTATED_VALUE @onEnumValue + OTHER_VALUE + } + + input InputType { + key: String! + answer: Int = 42 + } + + input AnnotatedInput @onInputObjectType { + annotatedField: Type @onField + } + + directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT + + directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT + schema + } + + it "generate" do + assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string + end + + it "doesn't mutate the document" do + assert_equal document.to_query_string, document.to_query_string + end end end end end