1
- from graphql .type import (
2
- GraphQLField ,
3
- GraphQLID ,
4
- GraphQLInt ,
5
- GraphQLInterfaceType ,
6
- GraphQLList ,
7
- GraphQLNonNull ,
8
- GraphQLObjectType ,
9
- GraphQLSchema ,
10
- GraphQLString ,
11
- )
1
+ from graphql .utilities import build_schema
12
2
from graphql .validation import OverlappingFieldsCanBeMergedRule
13
3
from graphql .validation .rules .overlapping_fields_can_be_merged import (
14
4
fields_conflict_message ,
@@ -529,101 +519,69 @@ def ignores_unknown_fragments():
529
519
530
520
def describe_return_types_must_be_unambiguous ():
531
521
532
- SomeBox = GraphQLInterfaceType (
533
- "SomeBox" ,
534
- lambda : {
535
- "deepBox" : GraphQLField (SomeBox ),
536
- "unrelatedField" : GraphQLField (GraphQLString ),
537
- },
538
- )
522
+ schema = build_schema (
523
+ """
524
+ interface SomeBox {
525
+ deepBox: SomeBox
526
+ unrelatedField: String
527
+ }
539
528
540
- StringBox = GraphQLObjectType (
541
- "StringBox" ,
542
- lambda : {
543
- "scalar" : GraphQLField (GraphQLString ),
544
- "deepBox" : GraphQLField (StringBox ),
545
- "unrelatedField" : GraphQLField (GraphQLString ),
546
- "listStringBox" : GraphQLField (GraphQLList (StringBox )),
547
- "stringBox" : GraphQLField (StringBox ),
548
- "intBox" : GraphQLField (IntBox ),
549
- },
550
- interfaces = [SomeBox ],
551
- )
529
+ type StringBox implements SomeBox {
530
+ scalar: String
531
+ deepBox: StringBox
532
+ unrelatedField: String
533
+ listStringBox: [StringBox]
534
+ stringBox: StringBox
535
+ intBox: IntBox
536
+ }
552
537
553
- IntBox = GraphQLObjectType (
554
- "IntBox" ,
555
- lambda : {
556
- "scalar" : GraphQLField (GraphQLInt ),
557
- "deepBox" : GraphQLField (IntBox ),
558
- "unrelatedField" : GraphQLField (GraphQLString ),
559
- "listStringBox" : GraphQLField (GraphQLList (StringBox )),
560
- "stringBox" : GraphQLField (StringBox ),
561
- "intBox" : GraphQLField (IntBox ),
562
- },
563
- interfaces = [SomeBox ],
564
- )
538
+ type IntBox implements SomeBox {
539
+ scalar: Int
540
+ deepBox: IntBox
541
+ unrelatedField: String
542
+ listStringBox: [StringBox]
543
+ stringBox: StringBox
544
+ intBox: IntBox
545
+ }
565
546
566
- NonNullStringBox1 = GraphQLInterfaceType (
567
- "NonNullStringBox1" , { " scalar" : GraphQLField ( GraphQLNonNull ( GraphQLString ))}
568
- )
547
+ interface NonNullStringBox1 {
548
+ scalar: String!
549
+ }
569
550
570
- NonNullStringBox1Impl = GraphQLObjectType (
571
- "NonNullStringBox1Impl" ,
572
- {
573
- "scalar" : GraphQLField (GraphQLNonNull (GraphQLString )),
574
- "deepBox" : GraphQLField (StringBox ),
575
- "unrelatedField" : GraphQLField (GraphQLString ),
576
- },
577
- interfaces = [SomeBox , NonNullStringBox1 ],
578
- )
551
+ type NonNullStringBox1Impl implements SomeBox & NonNullStringBox1 {
552
+ scalar: String!
553
+ unrelatedField: String
554
+ deepBox: SomeBox
555
+ }
579
556
580
- NonNullStringBox2 = GraphQLInterfaceType (
581
- "NonNullStringBox2" , { " scalar" : GraphQLField ( GraphQLNonNull ( GraphQLString ))}
582
- )
557
+ interface NonNullStringBox2 {
558
+ scalar: String!
559
+ }
583
560
584
- NonNullStringBox2Impl = GraphQLObjectType (
585
- "NonNullStringBox2Impl" ,
586
- {
587
- "scalar" : GraphQLField (GraphQLNonNull (GraphQLString )),
588
- "unrelatedField" : GraphQLField (GraphQLString ),
589
- "deepBox" : GraphQLField (StringBox ),
590
- },
591
- interfaces = [SomeBox , NonNullStringBox2 ],
592
- )
561
+ type NonNullStringBox2Impl implements SomeBox & NonNullStringBox2 {
562
+ scalar: String!
563
+ unrelatedField: String
564
+ deepBox: SomeBox
565
+ }
593
566
594
- Connection = GraphQLObjectType (
595
- "Connection" ,
596
- {
597
- "edges" : GraphQLField (
598
- GraphQLList (
599
- GraphQLObjectType (
600
- "Edge" ,
601
- {
602
- "node" : GraphQLField (
603
- GraphQLObjectType (
604
- "Node" ,
605
- {
606
- "id" : GraphQLField (GraphQLID ),
607
- "name" : GraphQLField (GraphQLString ),
608
- },
609
- )
610
- )
611
- },
612
- )
613
- )
614
- )
615
- },
616
- )
567
+ type Connection {
568
+ edges: [Edge]
569
+ }
617
570
618
- schema = GraphQLSchema (
619
- GraphQLObjectType (
620
- "QueryRoot" ,
621
- {
622
- "someBox" : GraphQLField (SomeBox ),
623
- "connection" : GraphQLField (Connection ),
624
- },
625
- ),
626
- types = [IntBox , StringBox , NonNullStringBox1Impl , NonNullStringBox2Impl ],
571
+ type Edge {
572
+ node: Node
573
+ }
574
+
575
+ type Node {
576
+ id: ID
577
+ name: String
578
+ }
579
+
580
+ type Query {
581
+ someBox: SomeBox
582
+ connection: Connection
583
+ }
584
+ """
627
585
)
628
586
629
587
def conflicting_return_types_which_potentially_overlap ():
@@ -1051,12 +1009,16 @@ def error_message_contains_hint_for_alias_conflict():
1051
1009
)
1052
1010
1053
1011
def works_for_field_names_that_are_js_keywords ():
1054
- FooType = GraphQLObjectType (
1055
- "Foo" , {"constructor" : GraphQLField (GraphQLString )}
1056
- )
1012
+ schema_with_keywords = build_schema (
1013
+ """
1014
+ type Foo {
1015
+ constructor: String
1016
+ }
1057
1017
1058
- schema_with_keywords = GraphQLSchema (
1059
- GraphQLObjectType ("query" , lambda : {"foo" : GraphQLField (FooType )})
1018
+ type Query {
1019
+ foo: Foo
1020
+ }
1021
+ """
1060
1022
)
1061
1023
1062
1024
expect_passes_rule_with_schema (
@@ -1072,10 +1034,16 @@ def works_for_field_names_that_are_js_keywords():
1072
1034
)
1073
1035
1074
1036
def works_for_field_names_that_are_python_keywords ():
1075
- FooType = GraphQLObjectType ("Foo" , {"class" : GraphQLField (GraphQLString )})
1037
+ schema_with_keywords = build_schema (
1038
+ """
1039
+ type Foo {
1040
+ class: String
1041
+ }
1076
1042
1077
- schema_with_keywords = GraphQLSchema (
1078
- GraphQLObjectType ("query" , lambda : {"foo" : GraphQLField (FooType )})
1043
+ type Query {
1044
+ foo: Foo
1045
+ }
1046
+ """
1079
1047
)
1080
1048
1081
1049
expect_passes_rule_with_schema (
0 commit comments