{"id":1460,"date":"2025-03-28T01:48:20","date_gmt":"2025-03-28T01:48:20","guid":{"rendered":"https:\/\/tiemensfamily.com\/timoncs\/?p=1460"},"modified":"2025-03-28T03:00:51","modified_gmt":"2025-03-28T03:00:51","slug":"fix-for-graphql-testing","status":"publish","type":"post","link":"https:\/\/tiemensfamily.com\/timoncs\/2025\/03\/28\/fix-for-graphql-testing\/","title":{"rendered":"Fix for GraphQL testing"},"content":{"rendered":"\n<p>You are here because you are following the &#8220;<a href=\"https:\/\/spring.io\/guides\/gs\/graphql-server\">Building a GraphQL service<\/a>&#8220;, and specifically the testing section using GraphQlTest, and you keep getting a runtime error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>java.lang.IllegalStateException: Failed to load ApplicationContext for &#91;MergedContextConfiguration@5b202ff testClass = com.tiemens.fullstack.controller.BookControllerTests, locations = &#91;], classes = &#91;com.tiemens.fullstack.FullstackApplication], contextInitializerClasses = &#91;], activeProfiles = &#91;], propertySourceDescriptors = &#91;], propertySourceProperties = &#91;\"org.springframework.boot.test.autoconfigure.graphql.GraphQlTestContextBootstrapper=true\"]<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphQlSource' defined in class path resource &#91;org\/springframework\/boot\/autoconfigure\/graphql\/GraphQlAutoConfiguration.class]: Failed to instantiate &#91;org.springframework.graphql.execution.GraphQlSource]: Factory method 'graphQlSource' threw exception with message: Name for argument of type &#91;java.lang.String] not specified, and parameter name information not found in class file either.<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate &#91;org.springframework.graphql.execution.GraphQlSource]: Factory method 'graphQlSource' threw exception with message: Name for argument of type &#91;java.lang.String] not specified, and parameter name information not found in class file either.<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Caused by: java.lang.IllegalArgumentException: Name for argument of type &#91;java.lang.String] not specified, and parameter name information not found in class file either.<\/code><\/pre>\n\n\n\n<p>The fix is in BookController, bookById: simply change &#8220;@Argument String id&#8221; to be &#8220;@Argument(&#8220;id&#8221;) String id&#8221;, as shown below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Controller\npublic class BookController {\n    @QueryMapping\n    public Book bookById(@Argument<strong>(\"id\")<\/strong> String id) {\n        return Book.getById(id);\n    }\n    ...etc...\n}<\/code><\/pre>\n\n\n\n<p>Magically injected error that is magically fixed.<\/p>\n\n\n\n<p>Note: this was caused by Spring Boot v3,4,1 (or 3.4, or 3.2 or something in the &#8220;3&#8221;s)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You are here because you are following the &#8220;Building a GraphQL service&#8220;, and specifically the testing section using GraphQlTest, and you keep getting a runtime error: The fix is in BookController, bookById: simply change &#8220;@Argument String id&#8221; to be &#8220;@Argument(&#8220;id&#8221;) &hellip; <a href=\"https:\/\/tiemensfamily.com\/timoncs\/2025\/03\/28\/fix-for-graphql-testing\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/posts\/1460"}],"collection":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/comments?post=1460"}],"version-history":[{"count":3,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/posts\/1460\/revisions"}],"predecessor-version":[{"id":1465,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/posts\/1460\/revisions\/1465"}],"wp:attachment":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/media?parent=1460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/categories?post=1460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/tags?post=1460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}