{"id":1161,"date":"2022-08-01T08:29:55","date_gmt":"2022-08-01T06:29:55","guid":{"rendered":"https:\/\/www.rocworks.at\/wordpress\/?p=1161"},"modified":"2022-08-01T08:31:08","modified_gmt":"2022-08-01T06:31:08","slug":"graphql-for-unity-how-to-set-headers-in-code","status":"publish","type":"post","link":"https:\/\/www.rocworks.at\/wordpress\/?p=1161","title":{"rendered":"GraphQL for Unity and how to set headers in code&#8230;"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If you use the <a href=\"https:\/\/u3d.as\/2D81\">GraqhQL for Unity<\/a> asset and if you want to set the headers on HTTP or Websockets in the code, then you must use the the <strong>GraphQLHttp<\/strong> or <strong>GraphQLWebsockets<\/strong> class. At the base class &#8220;GraphQL&#8221; there is no &#8220;Headers&#8221; property!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public GraphQLHttp MyGraphQL;\n\nvoid Start()\n{        \n    if (MyGraphQL != null)\n    {\n        MyGraphQL.Headers = new List&lt;Header&gt;()\n        {\n            new Header() { Key = \"token\", Value = \"secret\"}\n        };\n        ...\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then you can also execute a GraphQL query in the code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MyGraphQL.ExecuteQuery(\"query { test }\", null, (message) =&gt;\n{\n    if (message.Type == MessageType.GQL_DATA)\n    {\n        Debug.Log(\"Data: \" + message.Result.ToString());\n    }\n    else\n    {\n        Debug.Log(\"Error: \" + message.Type);\n    }\n});\n      \n   <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you use the GraqhQL for Unity asset and if you want to set the headers on HTTP or Websockets in the code, then you must use the the GraphQLHttp or GraphQLWebsockets class. At the base class &#8220;GraphQL&#8221; there is &hellip; <a href=\"https:\/\/www.rocworks.at\/wordpress\/?p=1161\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[48,49],"class_list":["post-1161","post","type-post","status-publish","format-standard","hentry","category-graphql","tag-graphql","tag-unity"],"_links":{"self":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1161"}],"version-history":[{"count":2,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1161\/revisions"}],"predecessor-version":[{"id":1163,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1161\/revisions\/1163"}],"wp:attachment":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}