@@ -45,6 +45,7 @@ public class GraphQLConfigSchemaNode extends SimpleNode {
45
45
private final GraphQLFile configurationEntryFile ;
46
46
47
47
private Map <String , GraphQLResolvedConfigData > projectsConfigData ;
48
+ private boolean performSchemaDiscovery = true ;
48
49
49
50
protected GraphQLConfigSchemaNode (Project project , GraphQLConfigManager configManager , GraphQLResolvedConfigData configData , VirtualFile configBaseDir ) {
50
51
super (project );
@@ -58,33 +59,44 @@ protected GraphQLConfigSchemaNode(Project project, GraphQLConfigManager configMa
58
59
// use the last part of the folder as name
59
60
myName = StringUtils .substringAfterLast (configBaseDir .getPath (), "/" );
60
61
}
61
- getPresentation ().setLocationString (configBaseDir .getPresentableUrl ());
62
- getPresentation ().setIcon (JSGraphQLIcons .Files .GraphQLSchema );
63
-
64
- final GraphQLTypeDefinitionRegistryServiceImpl registry = GraphQLTypeDefinitionRegistryServiceImpl .getService (myProject );
65
62
66
- configurationEntryFile = configManager .getConfigurationEntryFile (configData );
67
- endpoints = configManager .getEndpoints (configurationEntryFile .getVirtualFile ());
68
- schemaWithErrors = registry .getSchemaWithErrors (configurationEntryFile );
63
+ getPresentation ().setIcon (JSGraphQLIcons .Files .GraphQLSchema );
69
64
70
65
if (configData instanceof GraphQLConfigData ) {
66
+ getPresentation ().setLocationString (configBaseDir .getPresentableUrl ());
71
67
projectsConfigData = ((GraphQLConfigData ) configData ).projects ;
68
+ // this node is only considered a "real" schema that should be discovered if the config file doesn't use projects
69
+ // if the config uses projects we can't do discovery at the root level as that's likely to consider multiple distinct schemas
70
+ // as one with resulting re-declaration errors during validation
71
+ performSchemaDiscovery = projectsConfigData == null || projectsConfigData .isEmpty ();
72
72
}
73
73
74
+ if (performSchemaDiscovery ) {
75
+ final GraphQLTypeDefinitionRegistryServiceImpl registry = GraphQLTypeDefinitionRegistryServiceImpl .getService (myProject );
76
+ configurationEntryFile = configManager .getConfigurationEntryFile (configData );
77
+ endpoints = configManager .getEndpoints (configurationEntryFile .getVirtualFile ());
78
+ schemaWithErrors = registry .getSchemaWithErrors (configurationEntryFile );
79
+ } else {
80
+ schemaWithErrors = null ;
81
+ endpoints = null ;
82
+ configurationEntryFile = null ;
83
+ }
74
84
}
75
85
76
86
/**
77
87
* Gets whether this node contains a schema that includes the specified file
78
88
*/
79
89
public boolean representsFile (VirtualFile virtualFile ) {
80
90
if (virtualFile != null ) {
81
- if (virtualFile .equals (configFile )) {
91
+ if (virtualFile .equals (configFile )) {
82
92
return true ;
83
93
}
84
- final GraphQLNamedScope schemaScope = configManager .getSchemaScope (configurationEntryFile .getVirtualFile ());
85
- if (schemaScope != null ) {
86
- if (schemaScope .getPackageSet ().includesVirtualFile (virtualFile )) {
87
- return true ;
94
+ if (performSchemaDiscovery ) {
95
+ final GraphQLNamedScope schemaScope = configManager .getSchemaScope (configurationEntryFile .getVirtualFile ());
96
+ if (schemaScope != null ) {
97
+ if (schemaScope .getPackageSet ().includesVirtualFile (virtualFile )) {
98
+ return true ;
99
+ }
88
100
}
89
101
}
90
102
}
@@ -104,20 +116,23 @@ protected void update(PresentationData presentation) {
104
116
105
117
@ Override
106
118
public SimpleNode [] getChildren () {
107
- final List <SimpleNode > children = Lists .newArrayList (
108
- new GraphQLSchemaContentNode ( this , schemaWithErrors ),
109
- new GraphQLSchemaErrorsListNode (this , schemaWithErrors )
110
- );
119
+ final List <SimpleNode > children = Lists .newArrayList ();
120
+ if (performSchemaDiscovery ) {
121
+ children .add (new GraphQLSchemaContentNode (this , schemaWithErrors ));
122
+ children .add (new GraphQLSchemaErrorsListNode (this , schemaWithErrors ));
123
+ }
111
124
if (projectsConfigData != null && !projectsConfigData .isEmpty ()) {
112
125
children .add (new GraphQLConfigProjectsNode (this ));
113
126
}
114
- children .add (new GraphQLSchemaEndpointsListNode (this , endpoints ));
127
+ if (endpoints != null ) {
128
+ children .add (new GraphQLSchemaEndpointsListNode (this , endpoints ));
129
+ }
115
130
return children .toArray (SimpleNode .NO_CHILDREN );
116
131
}
117
132
118
133
@ Override
119
134
public boolean isAutoExpandNode () {
120
- return representsCurrentFile ();
135
+ return representsCurrentFile () || ! performSchemaDiscovery ;
121
136
}
122
137
123
138
@ NotNull
0 commit comments