@@ -860,6 +860,126 @@ export default function makeNewBuild(builder: SchemaBuilder): { ...Build } {
860860 ) ;
861861 } ,
862862 } ;
863+ } else if ( Type === GraphQLInterfaceType ) {
864+ const commonContext = {
865+ type : "GraphQLInterfaceType" ,
866+ scope,
867+ } ;
868+ newSpec = builder . applyHooks (
869+ this ,
870+ "GraphQLInterfaceType" ,
871+ newSpec ,
872+ commonContext ,
873+ `|${ newSpec . name } `
874+ ) ;
875+
876+ const rawSpec = newSpec ;
877+ newSpec = {
878+ ...newSpec ,
879+ fields : ( ) => {
880+ const processedFields = [ ] ;
881+ const fieldsContext = {
882+ ...commonContext ,
883+ Self,
884+ GraphQLInterfaceType : rawSpec ,
885+ fieldWithHooks : ( ( fieldName , spec , fieldScope ) => {
886+ if ( ! isString ( fieldName ) ) {
887+ throw new Error (
888+ "It looks like you forgot to pass the fieldName to `fieldWithHooks`, we're sorry this is currently necessary."
889+ ) ;
890+ }
891+ if ( ! fieldScope ) {
892+ throw new Error (
893+ "All calls to `fieldWithHooks` must specify a `fieldScope` " +
894+ "argument that gives additional context about the field so " +
895+ "that further plugins may more easily understand the field. " +
896+ "Keys within this object should contain the phrase 'field' " +
897+ "since they will be merged into the parent objects scope and " +
898+ "are not allowed to clash. If you really have no additional " +
899+ "information to give, please just pass `{}`."
900+ ) ;
901+ }
902+
903+ let newSpec = spec ;
904+ const context = {
905+ ...commonContext ,
906+ Self,
907+ scope : extend (
908+ extend (
909+ { ...scope } ,
910+ {
911+ fieldName,
912+ } ,
913+ `Within context for GraphQLInterfaceType '${ rawSpec . name } '`
914+ ) ,
915+ fieldScope ,
916+ `Extending scope for field '${ fieldName } ' within context for GraphQLInterfaceType '${ rawSpec . name } '`
917+ ) ,
918+ } ;
919+ if ( typeof newSpec === "function" ) {
920+ newSpec = newSpec ( context ) ;
921+ }
922+ newSpec = builder . applyHooks (
923+ this ,
924+ "GraphQLInterfaceType:fields:field" ,
925+ newSpec ,
926+ context ,
927+ `|${ getNameFromType ( Self ) } .fields.${ fieldName } `
928+ ) ;
929+ newSpec . args = newSpec . args || { } ;
930+ newSpec = {
931+ ...newSpec ,
932+ args : builder . applyHooks (
933+ this ,
934+ "GraphQLInterfaceType:fields:field:args" ,
935+ newSpec . args ,
936+ {
937+ ...context ,
938+ field : newSpec ,
939+ returnType : newSpec . type ,
940+ } ,
941+ `|${ getNameFromType ( Self ) } .fields.${ fieldName } `
942+ ) ,
943+ } ;
944+ const finalSpec = newSpec ;
945+ processedFields . push ( finalSpec ) ;
946+ return finalSpec ;
947+ } : FieldWithHooksFunction ) ,
948+ } ;
949+ let rawFields = rawSpec . fields || { } ;
950+ if ( typeof rawFields === "function" ) {
951+ rawFields = rawFields ( fieldsContext ) ;
952+ }
953+ const fieldsSpec = builder . applyHooks (
954+ this ,
955+ "GraphQLInterfaceType:fields" ,
956+ this . extend (
957+ { } ,
958+ rawFields ,
959+ `Default field included in newWithHooks call for '${
960+ rawSpec . name
961+ } '. ${ inScope . __origin || "" } `
962+ ) ,
963+ fieldsContext ,
964+ `|${ rawSpec . name } `
965+ ) ;
966+ // Finally, check through all the fields that they've all been processed; any that have not we should do so now.
967+ for ( const fieldName in fieldsSpec ) {
968+ const fieldSpec = fieldsSpec [ fieldName ] ;
969+ if ( processedFields . indexOf ( fieldSpec ) < 0 ) {
970+ // We've not processed this yet; process it now!
971+ fieldsSpec [ fieldName ] = fieldsContext . fieldWithHooks (
972+ fieldName ,
973+ fieldSpec ,
974+ {
975+ autoField : true , // We don't have any additional information
976+ }
977+ ) ;
978+ }
979+ }
980+ return fieldsSpec ;
981+ } ,
982+ } ;
863983 }
864984
865985 const finalSpec : ConfigType = newSpec ;
0 commit comments