0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Deno: GitLab で GraphQL を使う

Posted at

こちらのプログラムを Deno で書き換えました。
Curl: GitLab で GraphQL を使う

プログラム

get_data.sh
export ACCESS_TOKEN="glpat-******"
deno run --allow-all get_data.ts query.json
get_data.ts
// ---------------------------------------------------------------
//	get_data.ts
//
//					Apr/15/2023
//
// ---------------------------------------------------------------
import process from "node:process"

const file_in:string =Deno.args[0]
console.log (file_in)

const url = "https://gitlab.com/api/graphql"

const query:string = Deno.readTextFileSync (file_in,{ encoding: "utf8" })

console.log(query)

const headers = new Headers({
  "Authorization": `bearer ${process.env.ACCESS_TOKEN}`,
  "Content-Type": "application/json",
})

const response = await fetch(url, {
  method: "POST",
  headers: headers,
  body: query,
})

const data = await response.json()
console.log(data)

// ---------------------------------------------------------------
query.json
{"query": "query {currentUser {name location username webUrl}}"}

実行結果

$ ./get_data.sh 
query.json
{"query": "query {currentUser {name location username webUrl}}"}

{
  data: {
    currentUser: {
      name: "Uchida Masatomo",
      location: "栃木県",
      username: "ekzemplaro",
      webUrl: "https://gitlab.com/ekzemplaro"
    }
  }
}

確認したバージョン

$ deno --version
deno 1.32.4 (release, x86_64-unknown-linux-gnu)
v8 11.2.214.9
typescript 5.0.3
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?