{"id":1072,"date":"2020-01-22T20:38:19","date_gmt":"2020-01-23T02:38:19","guid":{"rendered":"http:\/\/tiemensfamily.com\/TimOnCS\/?p=1072"},"modified":"2020-01-22T20:38:19","modified_gmt":"2020-01-23T02:38:19","slug":"graphql-with-curl-examples","status":"publish","type":"post","link":"https:\/\/tiemensfamily.com\/timoncs\/2020\/01\/22\/graphql-with-curl-examples\/","title":{"rendered":"GraphQL with curl examples"},"content":{"rendered":"<p>GraphQL curl command examples, showing you both the curl command and the graphql schema.<\/p>\n<p>Project link: <a href=\"https:\/\/github.com\/kobylynskyi\/graphql-java-codegen-gradle-plugin\">graphql-java-codegen-gradle-plugin<\/a><\/p>\n<p>This is documentation for the combination of:<\/p>\n<ol>\n<li> A realistic <a href=\"https:\/\/github.com\/kobylynskyi\/graphql-java-codegen-gradle-plugin\/blob\/master\/graphql-codegen-gradle-plugin-example\/src\/main\/resources\/schema.graphqls\">graphql schema<\/a><\/li>\n<li>An actual <a href=\"https:\/\/github.com\/kobylynskyi\/graphql-java-codegen-gradle-plugin\/tree\/master\/graphql-codegen-gradle-plugin-example\/src\/main\/java\/io\/github\/kobylynskyi\/bikeshop\">Java server<\/a> that implements that graphql schema<\/li>\n<li>Using curl to issue graphql commands to that server<\/li>\n<\/ol>\n<p>It is <strong>amazing difficult<\/strong> to find all three of these together in one place.<\/p>\n<p>Process:<\/p>\n<ol>\n<li>clone git repository https:\/\/github.com\/kobylynskyi\/graphql-java-codegen-gradle-plugin<\/li>\n<li>cd graphql-java-codegen-gradle-plugin\/graphql-codegen-gradle-plugin-example<\/li>\n<li>echo &gt; settings.gradle<\/li>\n<li>gradle build<\/li>\n<li>start mongodb on port 27017 on localhost<\/li>\n<li>gradle run<br \/>\n  &#8212; this starts a server on port localhost:8080<\/li>\n<\/ol>\n<p>Then, in a different window, run these sample curl commands:<\/p>\n<p><strong>ADD:<\/strong><br \/>\nNotes:<br \/>\n   * Shows syntax for types: String, Int, BigDecimal, and enum<br \/>\n   * Only outputs &#8216;size&#8217; because that is what the query asked to get<br \/>\n   * Shows that &#8220;mutation&#8221; is still a &#8220;query&#8221;<br \/>\n   * Shows the correct quotation mark escaping, and where quotes are required and where they are not required<\/p>\n<pre>\ncurl  \\\n  -X POST \\\n  -H \"Content-Type: application\/json\" \\\n  -d '{ \"query\":  \"mutation {  newBike(bike : { type: ROAD, brand: \\\"foo\\\", size: \\\"big\\\", year: 2000, price: 123 }) { size } }\" }' \\\n  http:\/\/localhost:8080\/graphql\n<\/pre>\n<p>Result:<\/p>\n<pre>\n{\n  \"data\": {\n    \"newBike\": {\n      \"size\":\"big\"\n    }\n  }\n}\n<\/pre>\n<p><strong>FETCH:<\/strong><br \/>\nNotes:<br \/>\n    * shows formatting of &#8220;DateTime&#8221; field<\/p>\n<pre>\ncurl  \\\n  -X POST \\\n  -H \"Content-Type: application\/json\" \\\n  -d '{ \"query\":  \"query {  bikes { id type brand size year price addedDateTime} }\"  }' \\\n  http:\/\/localhost:8080\/graphql\n<\/pre>\n<p>Result:<\/p>\n<pre>\n{\n  \"data\": {\n    \"bikes\": [\n      {\n        \"id\": \"5e28ac4d64f0e8088f8bce47\",\n        \"type\": \"ROAD\",\n        \"brand\": \"foo\",\n        \"size\": \"big\",\n        \"year\": 2000,\n        \"price\": 123,\n        \"addedDateTime\": \"2020-01-22 14:10:53 -0600\"\n      }\n    ]\n  }\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>GraphQL curl command examples, showing you both the curl command and the graphql schema. Project link: graphql-java-codegen-gradle-plugin This is documentation for the combination of: A realistic graphql schema An actual Java server that implements that graphql schema Using curl to &hellip; <a href=\"https:\/\/tiemensfamily.com\/timoncs\/2020\/01\/22\/graphql-with-curl-examples\/\">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\/1072"}],"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=1072"}],"version-history":[{"count":0,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/posts\/1072\/revisions"}],"wp:attachment":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/media?parent=1072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/categories?post=1072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/tags?post=1072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}