npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

graphql-to-csv

v0.0.1

Published

Export GraqhQL Data to CSV

Downloads

5

Readme

graphql-to-csv

Export GraqhQL Data to CSV

install

npm install graphql-to-csv

usage

import { generate } from "graphql-to-csv";

const results = await generate({
  // mapping of CSV columns to data paths
  columns: [
    { name: "title", path: "title" }, // name and path are the same
    {
      name: "data_centers", // name of the column in the CSV output
      path: "dataCenters.shortName" // path to the relevant data in the GraphQL Response
    },
  ],

  // optional, type of pagination
  // currently the only option is "cursor", but we will add more
  pagination: "cursor",

  // where to set the cursor in the variables after the response
  cursor_set_path: "params.cursor",

  // GraphQL query
  query: `query CollectionsQuery($params: CollectionsInput) {
    collections(params: $params) {
      cursor
      items {
        dataCenters
        timeEnd
        timeStart
        title
      }
    }
  }`,

  // where the array of row-like items starts in the GraphQL response
  start: "data.collections.items",

  // GraphQL API Endpoint
  url: "https://graphql.earthdata.nasa.gov/api"
});

console.log(results.csv);
`"title","data_centers"
"'Latent reserves' within the Swiss NFI","WSL"
"(U-Th)/He ages from the Kukri Hills of southern Victoria Land","SYRACUSE/ES/TGIGRG"
"0.5 hour 1 M HCl extraction data for the Windmill Islands marine sediments","AU/AADC"
"1-100Hz ULF/ELF Electromagnetic Wave Observation at Syowa Station","TOHOKU/PAT"
"10 Days Synthesis of SPOT VEGETATION Images (VGT-S10)","VITO"
"10 m firn temperature data: LGB traverses 1990-95","AU/AADC"
"10 sec GPS ground tracking data","DE/GFZ/ISDC"
"10 year trend of levels of organochlorine pollutants in Antarctic seabirds","AU/AADC"
"10-HS Pfynwald","WSL"
"101.1 m long horizontal blue ice core collected from Scharffenbergbotnen, DML, Antarctica, in 2003/2004","U-LAPLAND/AC"
"12 Hourly Interpolated Surface Air Pressure from Buoys","ACADIS"
"12,000 year record of sea spray and minerogenic input from Emerald Lake, Macquarie Island","AU/AADC"
"12-Hourly Interpolated Surface Position from Buoys","ACADIS"
"12-Hourly Interpolated Surface Velocity from Buoys","ACADIS"
"14C of soil CO2 from IPY ITEX Cross Site Comparison","ACADIS"
"15 Minute Stream Flow Data: USGS (FIFE)","ORNL_DAAC"
"15 year Wilhelm II Land MSA and HOOH shallow ice core record from Mount Brown South (MBS)","AU/AADC"
"150 year MSA sea ice proxy record from Law Dome, Antarctica","AU/AADC"
"17O Excess from WAIS Divide, 0 to 25 ka BP, Version 1","USAP-DC"
"1982 Commodity Output by State and Input-Output Sector","USDA/ERS"`

advanced usage

  const { csv } = await generate({
    columns: [
      { name: "data_centers", path: "dataCenters.shortName" },
      { name: "concept_id", path: "conceptId" },
      { name: "short_name", path: "shortName" },
      { name: "title", path: "title" },
      { name: "time_end", path: "timeEnd" },
      { name: "time_start", path: "timeStart" }
    ],

    // if your cursor isn't name "cursor",
    // we won't be able to auto-detect it
    cursor_get_path: "collections.items.after",

    cursor_set_path: "params.cursor",

    // enable helpful console logging
    debug_level: 3,

    // total number of requests/pages
    max_requests: 5,
    pagination: "cursor",
    query: `query CollectionsQuery($params: CollectionsInput) { ...  }`,

    // sometimes your second and later requests are different than the first
    query_subsequent: `query NextCollectionsQuery...`,

    start: "data.collections.items",
    url: "https://graphql.earthdata.nasa.gov/api"
  });