11package graphql.i18n
22
33import graphql.AssertException
4+ import graphql.ExecutionInput
5+ import graphql.TestUtil
46import graphql.i18n.I18n.BundleType
57import spock.lang.Specification
68
@@ -14,6 +16,43 @@ class I18nTest extends Specification {
1416 thrown(AssertException )
1517 }
1618
19+ def " missing resource bundles default to a base version" () {
20+ // see https://saimana.com/list-of-country-locale-code/
21+
22+ def expected = " Validation error ({0}) : Type '{1}' definition is not executable"
23+
24+ when :
25+ def i18n = I18n . i18n(BundleType.Validation , Locale . ENGLISH )
26+ def msg = i18n. msg(" ExecutableDefinitions.notExecutableType" )
27+
28+ then :
29+ msg == expected
30+
31+ when :
32+ i18n = I18n . i18n(BundleType.Validation , Locale . CHINESE )
33+ msg = i18n. msg(" ExecutableDefinitions.notExecutableType" )
34+ then :
35+ msg == expected
36+
37+ when :
38+ i18n = I18n . i18n(BundleType.Validation , new Locale (" en" , " IN" )) // India
39+ msg = i18n. msg(" ExecutableDefinitions.notExecutableType" )
40+ then :
41+ msg == expected
42+
43+ when :
44+ i18n = I18n . i18n(BundleType.Validation , new Locale (" en" , " FJ" )) // Fiji
45+ msg = i18n. msg(" ExecutableDefinitions.notExecutableType" )
46+ then :
47+ msg == expected
48+
49+ when :
50+ i18n = I18n . i18n(BundleType.Validation , new Locale (" " )) // Nothing
51+ msg = i18n. msg(" ExecutableDefinitions.notExecutableType" )
52+ then :
53+ msg == expected
54+ }
55+
1756 def " all enums have resources and decent shapes" () {
1857 when :
1958 def bundleTypes = BundleType . values()
@@ -34,6 +73,59 @@ class I18nTest extends Specification {
3473 message == " Validierungsfehler ({0}) : Type definition '{1}' ist nicht ausführbar"
3574 }
3675
76+ def " integration test of valid messages" () {
77+ def sdl = """
78+ type Query {
79+ field(arg : Int) : Subselection
80+ }
81+
82+ type Subselection {
83+ name : String
84+ }
85+ """
86+ def graphQL = TestUtil . graphQL(sdl). build()
87+
88+
89+ when :
90+ def locale = new Locale (" en" , " IN" )
91+ def ei = ExecutionInput . newExecutionInput(). query(" query missingSubselectionQ { field(arg : 1) }" )
92+ .locale(locale)
93+ .build()
94+ def er = graphQL. execute(ei)
95+ then :
96+ ! er. errors. isEmpty()
97+ er. errors[0 ]. message == " Validation error (SubselectionRequired@[field]) : Subselection required for type 'Subselection' of field 'field'"
98+
99+ when :
100+ locale = Locale . GERMANY
101+ ei = ExecutionInput . newExecutionInput(). query(" query missingSubselectionQ { field(arg : 1) }" )
102+ .locale(locale)
103+ .build()
104+ er = graphQL. execute(ei)
105+ then :
106+ ! er. errors. isEmpty()
107+ er. errors[0 ]. message == " Validierungsfehler (SubselectionRequired@[field]) : Unterauswahl erforderlich für Typ 'Subselection' des Feldes 'field'"
108+
109+ when :
110+ locale = Locale . getDefault()
111+ ei = ExecutionInput . newExecutionInput(). query(" query missingSubselectionQ { field(arg : 1) }" )
112+ .locale(locale)
113+ .build()
114+ er = graphQL. execute(ei)
115+ then :
116+ ! er. errors. isEmpty()
117+ er. errors[0 ]. message == " Validation error (SubselectionRequired@[field]) : Subselection required for type 'Subselection' of field 'field'"
118+
119+ when :
120+ // no locale - it should default
121+ ei = ExecutionInput . newExecutionInput(). query(" query missingSubselectionQ { field(arg : 1) }" )
122+ .build()
123+ er = graphQL. execute(ei)
124+ then :
125+ ! er. errors. isEmpty()
126+ er. errors[0 ]. message == " Validation error (SubselectionRequired@[field]) : Subselection required for type 'Subselection' of field 'field'"
127+ }
128+
37129 static def assertBundleStaticShape (ResourceBundle bundle ) {
38130 def enumeration = bundle. getKeys()
39131 while (enumeration. hasMoreElements()) {
0 commit comments