@@ -685,7 +685,7 @@ describe(`Build schema`, () => {
685
685
)
686
686
} )
687
687
688
- it ( `does not merge plugin-defined type with type defined by other plugin` , async ( ) => {
688
+ it ( `warns when merging plugin-defined type with type defined by other plugin` , async ( ) => {
689
689
createTypes (
690
690
`type PluginDefined implements Node { foo: Int, baz: PluginDefinedNested }
691
691
type PluginDefinedNested { foo: Int }` ,
@@ -703,28 +703,32 @@ describe(`Build schema`, () => {
703
703
const schema = await buildSchema ( )
704
704
const nestedFields = schema . getType ( `PluginDefinedNested` ) . getFields ( )
705
705
const fields = schema . getType ( `PluginDefined` ) . getFields ( )
706
- expect ( Object . keys ( nestedFields ) ) . toEqual ( [ `foo` ] )
706
+ expect ( Object . keys ( nestedFields ) ) . toEqual ( [ `foo` , `bar` ] )
707
707
expect ( Object . keys ( fields ) ) . toEqual ( [
708
708
`foo` ,
709
709
`baz` ,
710
+ `bar` ,
711
+ `qux` ,
710
712
`id` ,
711
713
`parent` ,
712
714
`children` ,
713
715
`internal` ,
714
716
] )
715
717
expect ( report . warn ) . toHaveBeenCalledWith (
716
- `Plugin \`some-other-gatsby-plugin\` tried to define the GraphQL type ` +
718
+ `Plugin \`some-other-gatsby-plugin\` has customized the GraphQL type ` +
717
719
`\`PluginDefinedNested\`, which has already been defined by the plugin ` +
718
- `\`some-gatsby-plugin\`.`
720
+ `\`some-gatsby-plugin\`. ` +
721
+ `This could potentially cause conflicts.`
719
722
)
720
723
expect ( report . warn ) . toHaveBeenCalledWith (
721
- `Plugin \`some-other-gatsby-plugin\` tried to define the GraphQL type ` +
724
+ `Plugin \`some-other-gatsby-plugin\` has customized the GraphQL type ` +
722
725
`\`PluginDefined\`, which has already been defined by the plugin ` +
723
- `\`some-gatsby-plugin\`.`
726
+ `\`some-gatsby-plugin\`. ` +
727
+ `This could potentially cause conflicts.`
724
728
)
725
729
} )
726
730
727
- it ( `does not merge plugin-defined type (Type Builder) with type defined by other plugin` , async ( ) => {
731
+ it ( `warns when merging plugin-defined type (Type Builder) with type defined by other plugin` , async ( ) => {
728
732
createTypes (
729
733
`type PluginDefined implements Node { foo: Int, baz: PluginDefinedNested }
730
734
type PluginDefinedNested { foo: Int }` ,
@@ -759,28 +763,34 @@ describe(`Build schema`, () => {
759
763
const schema = await buildSchema ( )
760
764
const nestedFields = schema . getType ( `PluginDefinedNested` ) . getFields ( )
761
765
const fields = schema . getType ( `PluginDefined` ) . getFields ( )
762
- expect ( Object . keys ( nestedFields ) ) . toEqual ( [ `foo` ] )
766
+ expect ( Object . keys ( nestedFields ) ) . toEqual ( [ `foo` , `bar` ] )
763
767
expect ( Object . keys ( fields ) ) . toEqual ( [
764
768
`foo` ,
765
769
`baz` ,
770
+ `bar` ,
771
+ `qux` ,
766
772
`id` ,
767
773
`parent` ,
768
774
`children` ,
769
775
`internal` ,
770
776
] )
771
777
expect ( report . warn ) . toHaveBeenCalledWith (
772
- `Plugin \`some-other-gatsby-plugin\` tried to define the GraphQL type ` +
778
+ `Plugin \`some-other-gatsby-plugin\` has customized the GraphQL type ` +
773
779
`\`PluginDefinedNested\`, which has already been defined by the plugin ` +
774
- `\`some-gatsby-plugin\`.`
780
+ `\`some-gatsby-plugin\`. ` +
781
+ `This could potentially cause conflicts.`
775
782
)
776
783
expect ( report . warn ) . toHaveBeenCalledWith (
777
- `Plugin \`some-other-gatsby-plugin\` tried to define the GraphQL type ` +
784
+ `Plugin \`some-other-gatsby-plugin\` has customized the GraphQL type ` +
778
785
`\`PluginDefined\`, which has already been defined by the plugin ` +
779
- `\`some-gatsby-plugin\`.`
786
+ `\`some-gatsby-plugin\`. ` +
787
+ `This could potentially cause conflicts.`
780
788
)
781
789
} )
782
790
783
- it ( `does not merge plugin-defined type (graphql-js) with type defined by other plugin` , async ( ) => {
791
+ // FIXME: Fails with: Error: Cannot get field 'foo' from type 'PluginDefinedNested'. Field does not exist.
792
+ // same as "merges user-defined type (graphql-js) with plugin-defined type"
793
+ it . skip ( `warns when merging plugin-defined type (graphql-js) with type defined by other plugin` , async ( ) => {
784
794
createTypes (
785
795
`type PluginDefined implements Node { foo: Int, baz: PluginDefinedNested }
786
796
type PluginDefinedNested { foo: Int }` ,
@@ -807,27 +817,95 @@ describe(`Build schema`, () => {
807
817
const schema = await buildSchema ( )
808
818
const nestedFields = schema . getType ( `PluginDefinedNested` ) . getFields ( )
809
819
const fields = schema . getType ( `PluginDefined` ) . getFields ( )
810
- expect ( Object . keys ( nestedFields ) ) . toEqual ( [ `foo` ] )
820
+ expect ( Object . keys ( nestedFields ) ) . toEqual ( [ `foo` , `bar` ] )
811
821
expect ( Object . keys ( fields ) ) . toEqual ( [
812
822
`foo` ,
813
823
`baz` ,
824
+ `bar` ,
825
+ `qux` ,
814
826
`id` ,
815
827
`parent` ,
816
828
`children` ,
817
829
`internal` ,
818
830
] )
819
831
expect ( report . warn ) . toHaveBeenCalledWith (
820
- `Plugin \`some-other-gatsby-plugin\` tried to define the GraphQL type ` +
832
+ `Plugin \`some-other-gatsby-plugin\` has customized the GraphQL type ` +
821
833
`\`PluginDefinedNested\`, which has already been defined by the plugin ` +
822
834
`\`some-gatsby-plugin\`.`
823
835
)
824
836
expect ( report . warn ) . toHaveBeenCalledWith (
825
- `Plugin \`some-other-gatsby-plugin\` tried to define the GraphQL type ` +
837
+ `Plugin \`some-other-gatsby-plugin\` has customized the GraphQL type ` +
826
838
`\`PluginDefined\`, which has already been defined by the plugin ` +
827
839
`\`some-gatsby-plugin\`.`
828
840
)
829
841
} )
830
842
843
+ it ( `warns when merging plugin-defined type with built-in type` , async ( ) => {
844
+ createTypes ( `type SitePage implements Node { bar: Int }` , {
845
+ name : `some-gatsby-plugin` ,
846
+ } )
847
+ const schema = await buildSchema ( )
848
+ const fields = schema . getType ( `SitePage` ) . getFields ( )
849
+ expect ( Object . keys ( fields ) ) . toEqual ( [
850
+ `path` ,
851
+ `component` ,
852
+ `internalComponentName` ,
853
+ `componentChunkName` ,
854
+ `matchPath` ,
855
+ `bar` ,
856
+ `id` ,
857
+ `parent` ,
858
+ `children` ,
859
+ `internal` ,
860
+ ] )
861
+ expect ( report . warn ) . toHaveBeenCalledWith (
862
+ `Plugin \`some-gatsby-plugin\` has customized the built-in Gatsby GraphQL type ` +
863
+ `\`SitePage\`. This is allowed, but could potentially cause conflicts.`
864
+ )
865
+ } )
866
+
867
+ it ( `warns when merging plugin-defined type (Type Builder) with built-in type` , async ( ) => {
868
+ createTypes (
869
+ [
870
+ buildObjectType ( {
871
+ name : `SitePage` ,
872
+ interfaces : [ `Node` ] ,
873
+ extensions : {
874
+ infer : false ,
875
+ } ,
876
+ fields : {
877
+ bar : `Int` ,
878
+ } ,
879
+ } ) ,
880
+ ] ,
881
+ {
882
+ name : `some-gatsby-plugin` ,
883
+ }
884
+ )
885
+ const schema = await buildSchema ( )
886
+ const fields = schema . getType ( `SitePage` ) . getFields ( )
887
+ expect ( Object . keys ( fields ) ) . toEqual ( [
888
+ `path` ,
889
+ `component` ,
890
+ `internalComponentName` ,
891
+ `componentChunkName` ,
892
+ `matchPath` ,
893
+ `bar` ,
894
+ `id` ,
895
+ `parent` ,
896
+ `children` ,
897
+ `internal` ,
898
+ ] )
899
+ expect ( report . warn ) . toHaveBeenCalledWith (
900
+ `Plugin \`some-gatsby-plugin\` has customized the built-in Gatsby GraphQL type ` +
901
+ `\`SitePage\`. This is allowed, but could potentially cause conflicts.`
902
+ )
903
+ } )
904
+
905
+ it . todo (
906
+ `warns when merging plugin-defined type (graphql-js) with built-in type`
907
+ )
908
+
831
909
it ( `extends fieldconfigs when merging types` , async ( ) => {
832
910
createTypes (
833
911
buildObjectType ( {
0 commit comments