private OutputTypeModel AnalyzeWithHoistedFragment( IDocumentAnalyzerContext context, FieldSelection fieldSelection, SelectionSetVariants selectionVariants, string fragmentName) { FragmentNode?returnTypeFragment = FragmentHelper.CreateFragmentNode( selectionVariants.Variants[0], fieldSelection.Path, appendTypeName: true); returnTypeFragment = FragmentHelper.GetFragment(returnTypeFragment, fragmentName); if (returnTypeFragment is null) { // TODO : throw helper throw new GraphQLException( "The specified return fragment does not exist."); } OutputTypeModel returnType = FragmentHelper.CreateInterface(context, returnTypeFragment, fieldSelection.Path); context.RegisterSelectionSet( returnType.Type, selectionVariants.ReturnType.SyntaxNode, returnType.SelectionSet); foreach (SelectionSet selectionSet in selectionVariants.Variants) { returnTypeFragment = FragmentHelper.CreateFragmentNode( selectionSet, fieldSelection.Path, appendTypeName: true); returnTypeFragment = FragmentHelper.RewriteForConcreteType(returnTypeFragment); if (FragmentHelper.GetFragment(returnTypeFragment, fragmentName) is null) { // TODO : throw helper throw new GraphQLException( "The specified return fragment must be implement by all type fragments."); } OutputTypeModel @interface = FragmentHelper.CreateInterface( context, returnTypeFragment, fieldSelection.Path, new[] { returnType }); OutputTypeModel @class = FragmentHelper.CreateClass( context, returnTypeFragment, selectionSet, @interface); context.RegisterSelectionSet( selectionSet.Type, selectionSet.SyntaxNode, @class.SelectionSet); } return(returnType); }
private OutputTypeModel AnalyzeWithHoistedFragment( IDocumentAnalyzerContext context, FieldSelection fieldSelection, SelectionSetVariants selectionVariants, string fragmentName) { FragmentNode?returnTypeFragment = FragmentHelper.CreateFragmentNode( selectionVariants.Variants[0], fieldSelection.Path, appendTypeName: true); returnTypeFragment = FragmentHelper.GetFragment(returnTypeFragment, fragmentName); if (returnTypeFragment is null) { throw ThrowHelper.ReturnFragmentDoesNotExist(); } OutputTypeModel returnType = FragmentHelper.CreateInterface(context, returnTypeFragment, fieldSelection.Path); context.RegisterSelectionSet( returnType.Type, selectionVariants.ReturnType.SyntaxNode, returnType.SelectionSet); foreach (SelectionSet selectionSet in selectionVariants.Variants) { returnTypeFragment = FragmentHelper.CreateFragmentNode( selectionSet, fieldSelection.Path, appendTypeName: true); returnTypeFragment = FragmentHelper.RewriteForConcreteType(returnTypeFragment); if (FragmentHelper.GetFragment(returnTypeFragment, fragmentName) is null) { throw ThrowHelper.FragmentMustBeImplementedByAllTypeFragments(); } OutputTypeModel @interface = FragmentHelper.CreateInterface( context, returnTypeFragment, fieldSelection.Path, new[] { returnType }); OutputTypeModel @class = FragmentHelper.CreateClass( context, returnTypeFragment, selectionSet, @interface); context.RegisterSelectionSet( selectionSet.Type, selectionSet.SyntaxNode, @class.SelectionSet); } return(returnType); }