@@ -1790,4 +1790,127 @@ interface NonNullFieldComboApi {
17901790 contents .contains ("@Deprecated String id" );
17911791 contents .contains ("String email" );
17921792 }
1793+
1794+ @ Test
1795+ void useAliasForFieldNamesGeneratesAliasedInnerRecords () {
1796+ var source =
1797+ JavaFileObjects .forSourceString (
1798+ "test.AliasApi" ,
1799+ """
1800+ package test;
1801+
1802+ import feign.graphql.GraphqlSchema;
1803+ import feign.graphql.GraphqlQuery;
1804+
1805+ @GraphqlSchema(value = "test-schema.graphql", useAliasForFieldNames = true)
1806+ interface AliasApi {
1807+ @GraphqlQuery(\"""
1808+ {
1809+ starship(id: "1") {
1810+ id name
1811+ specification: specs { lengthMeters classification }
1812+ currentLocation: location { planet sector }
1813+ }
1814+ }\""")
1815+ StarshipResult getStarship();
1816+ }
1817+ """ );
1818+
1819+ var compilation = javac ().withProcessors (new GraphqlSchemaProcessor ()).compile (source );
1820+
1821+ assertThat (compilation ).succeeded ();
1822+
1823+ var contents =
1824+ assertThat (compilation ).generatedSourceFile ("test.StarshipResult" ).contentsAsUtf8String ();
1825+ contents .contains ("Optional<Specification> specification" );
1826+ contents .contains ("Optional<CurrentLocation> currentLocation" );
1827+ contents .contains ("public record Specification(" );
1828+ contents .contains ("public record CurrentLocation(" );
1829+ }
1830+
1831+ @ Test
1832+ void useAliasForFieldNamesDisabledUsesFieldName () {
1833+ var source =
1834+ JavaFileObjects .forSourceString (
1835+ "test.NoAliasApi" ,
1836+ """
1837+ package test;
1838+
1839+ import feign.graphql.GraphqlSchema;
1840+ import feign.graphql.GraphqlQuery;
1841+
1842+ @GraphqlSchema(value = "test-schema.graphql", useAliasForFieldNames = false)
1843+ interface NoAliasApi {
1844+ @GraphqlQuery(\"""
1845+ {
1846+ starship(id: "1") {
1847+ id name
1848+ specification: specs { lengthMeters classification }
1849+ currentLocation: location { planet sector }
1850+ }
1851+ }\""")
1852+ StarshipResult getStarship();
1853+ }
1854+ """ );
1855+
1856+ var compilation = javac ().withProcessors (new GraphqlSchemaProcessor ()).compile (source );
1857+
1858+ assertThat (compilation ).succeeded ();
1859+
1860+ var contents =
1861+ assertThat (compilation ).generatedSourceFile ("test.StarshipResult" ).contentsAsUtf8String ();
1862+ contents .contains ("Optional<Specs> specs" );
1863+ contents .contains ("Optional<Location> location" );
1864+ contents .contains ("public record Specs(" );
1865+ contents .contains ("public record Location(" );
1866+ }
1867+
1868+ @ Test
1869+ void useAliasForFieldNamesMethodOverridesClassLevel () {
1870+ var source =
1871+ JavaFileObjects .forSourceString (
1872+ "test.AliasOverrideApi" ,
1873+ """
1874+ package test;
1875+
1876+ import feign.graphql.GraphqlSchema;
1877+ import feign.graphql.GraphqlQuery;
1878+ import feign.graphql.Toggle;
1879+
1880+ @GraphqlSchema(value = "test-schema.graphql", useAliasForFieldNames = false)
1881+ interface AliasOverrideApi {
1882+ @GraphqlQuery(value = \"""
1883+ {
1884+ starship(id: "1") {
1885+ id name
1886+ specification: specs { lengthMeters classification }
1887+ }
1888+ }\""", useAliasForFieldNames = Toggle.TRUE)
1889+ AliasedResult getAliased();
1890+
1891+ @GraphqlQuery(\"""
1892+ {
1893+ starship(id: "1") {
1894+ id name
1895+ specification: specs { lengthMeters classification }
1896+ }
1897+ }\""")
1898+ PlainResult getPlain();
1899+ }
1900+ """ );
1901+
1902+ var compilation = javac ().withProcessors (new GraphqlSchemaProcessor ()).compile (source );
1903+
1904+ assertThat (compilation ).succeeded ();
1905+
1906+ var aliased =
1907+ assertThat (compilation ).generatedSourceFile ("test.AliasedResult" ).contentsAsUtf8String ();
1908+ aliased .contains ("Optional<Specification> specification" );
1909+ aliased .contains ("public record Specification(" );
1910+
1911+ var plain =
1912+ assertThat (compilation ).generatedSourceFile ("test.PlainResult" ).contentsAsUtf8String ();
1913+ plain .contains ("Optional<Specs> specs" );
1914+ plain .contains ("public record Specs(" );
1915+ }
17931916}
0 commit comments