@ndlib/graphql-harvest

1.3.0 • Public • Published

GraphQL Harvest

An NPM plugin to fetch data from an arbitrary GraphQL data source

Configuration Parameters Needed

  • You will need a set of GraphQL queries in one or more files in a specified folder
  • If you have multiple files with queries that need to be run, you must import the queries into an index.ts file
  • An index.ts files is required - an example is given below
  • You will need an output directory where the retrieved data will be stored
  • You will need to name your query call to the GraphQL endpoint
  • You will need to full URL to your GraphQL endpoint

In Development Environment

  • Globally install typescript
  • There are several node modules listed in the dev dependencies list that should get installed locally - those are required for correct TypeScript type identification
  • If you are using this with Gatsby you will need to add parameters to your gatsby-config.ts file

Example of use

How to use (in gatsby-config.ts):

include * from './content/graphql'

module.exports = {
  plugins: [
    ...
    {
      resolve: '@ndlib/graphql-harvest',
      options: {
        query_name: <any-name-you-want>,
        graphql_endpoint: <full-url-to-graphql-endpoint>,
        query_types: <included-module-with-graphql-queries-present>,
        results_output_path: <path-to-output-folder-where-results-are-stored>
      }
    },
    ...
  ]
}

Example of index.ts file that assigned to the query_types folder:

export * as people from './people'
export * as subjects from './subjects'
export * as teams from './teams'
export * as units from './units'
export * as universityCommittees from './universityCommittees'

Each of the types referenced above will have a GraphQL query in it and will be included at harvest time. A corresponding JSON file will be created in the output folder named for the type it represents. For example, in the above index.ts file, a people.json file will be created upon completion of the harvest assuming that the query is syntactically correct and the endpoint provides data matching the query.

Parameter Description Required
query_name An arbitrary that will get passed to the endpoint which can be used to track query execution in the endpoint log files yes
graphql_endpoint The full URL to the GraphQL endpoint yes
query_types Included at the top of the gatsby_config.ts file - an index.(js|ts) file which includes all of the types being queried yes
results_output_path The directory where the output files will be written - one JSON file per type included in the index.(js|ts) file yes

Readme

Keywords

Package Sidebar

Install

npm i @ndlib/graphql-harvest

Weekly Downloads

21

Version

1.3.0

License

Apache-2.0

Unpacked Size

1.46 MB

Total Files

47

Last publish

Collaborators

  • michaelrunyonnd
  • nealfwilliams-nd
  • thanstra
  • robertjonfox
  • danthewolfe
  • stevemattison