@@ -75,6 +75,10 @@ const buildSchema = async ({
75
75
} )
76
76
// const { printSchema } = require(`graphql`)
77
77
const schema = schemaComposer . buildSchema ( )
78
+
79
+ // Freeze all type composers except SitePage (as we will rebuild it at a later stage)
80
+ freezeTypeComposers ( schemaComposer , new Set ( [ `SitePage` ] ) )
81
+
78
82
// console.log(printSchema(schema))
79
83
return schema
80
84
}
@@ -121,6 +125,25 @@ module.exports = {
121
125
rebuildSchemaWithSitePage,
122
126
}
123
127
128
+ // Workaround for https://github.com/graphql-compose/graphql-compose/issues/319
129
+ // FIXME: remove this when fixed in graphql-compose
130
+ const freezeTypeComposers = ( schemaComposer , excluded ) => {
131
+ Array . from ( schemaComposer . values ( ) ) . forEach ( tc => {
132
+ const isCompositeTC =
133
+ tc instanceof ObjectTypeComposer || tc instanceof InterfaceTypeComposer
134
+
135
+ if ( isCompositeTC && ! excluded . has ( tc . getTypeName ( ) ) ) {
136
+ // typeComposer.getType() actually mutates the underlying GraphQL type
137
+ // and always re-assigns type._fields with a thunk.
138
+ // It causes continuous redundant field re-definitions when running queries
139
+ // (affects performance significantly).
140
+ // Prevent the mutation and "freeze" the type:
141
+ const type = tc . getType ( )
142
+ tc . getType = ( ) => type
143
+ }
144
+ } )
145
+ }
146
+
124
147
const updateSchemaComposer = async ( {
125
148
schemaComposer,
126
149
types,
0 commit comments