{"id":46957,"library":"apollo-datasource-graphql","title":"Apollo GraphQL DataSource","description":"A library for creating Apollo DataSources that connect to an existing GraphQL API. Current version is 1.3.2. It provides a simple way to integrate external GraphQL services into Apollo Server, similar to RESTDataSource but for GraphQL. Key differentiator: allows using Apollo Server's data source layer with GraphQL APIs, enabling caching, deduplication, and error handling. It is designed for Apollo Server 2.0 and uses GraphQL queries/mutations to fetch data. Note that this project is not actively maintained and has limited test coverage.","status":"maintenance","version":"1.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/poetic/apollo-datasource-graphql","tags":["javascript","apollo","datasource","graphql"],"install":[{"cmd":"npm install apollo-datasource-graphql","lang":"bash","label":"npm"},{"cmd":"yarn add apollo-datasource-graphql","lang":"bash","label":"yarn"},{"cmd":"pnpm add apollo-datasource-graphql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for parsing GraphQL documents and executing queries","package":"graphql","optional":false},{"reason":"Base class for Apollo DataSource","package":"apollo-datasource","optional":false}],"imports":[{"note":"ESM-only; CommonJS require will not work because package type is module","wrong":"const { GraphQLDataSource } = require('apollo-datasource-graphql')","symbol":"GraphQLDataSource","correct":"import { GraphQLDataSource } from 'apollo-datasource-graphql'"},{"note":"There is no default export; only named export GraphQLDataSource","wrong":"import { default } from 'apollo-datasource-graphql'","symbol":"default export","correct":"import ApolloGraphQLDataSource from 'apollo-datasource-graphql'"},{"note":"If only using for type checking, prefer type import to avoid bundling","wrong":"import { GraphQLDataSource } from 'apollo-datasource-graphql'","symbol":"type imports","correct":"import type { GraphQLDataSource } from 'apollo-datasource-graphql'"}],"quickstart":{"code":"import { GraphQLDataSource } from 'apollo-datasource-graphql';\nimport { gql } from 'apollo-server-express';\n\nconst GET_USER = gql`\n  query GetUser($id: ID!) {\n    user(id: $id) {\n      id\n      name\n    }\n  }\n`;\n\nclass UserAPI extends GraphQLDataSource {\n  baseURL = 'https://api.example.com/graphql';\n\n  async getUser(id: string) {\n    const response = await this.query(GET_USER, {\n      variables: { id },\n    });\n    return response.data.user;\n  }\n\n  willSendRequest(request: any) {\n    request.headers = request.headers || {};\n    request.headers.authorization = this.context.token;\n  }\n}\n\nexport { UserAPI };","lang":"typescript","description":"Defines a GraphQLDataSource subclass that connects to an external GraphQL API, sets auth headers, and runs a query."},"warnings":[{"fix":"Consider forking the repository or using RESTDataSource if possible.","message":"Package is not actively maintained; last release was in 2019. No test suite exists. Use with caution.","severity":"gotcha","affected_versions":"all"},{"fix":"Use import syntax or ensure your project is also ESM.","message":"CommonJS require() will not work. The package is ESM-only (type: module in package.json).","severity":"gotcha","affected_versions":">=1.3.0"},{"fix":"Set baseURL without trailing slash, e.g., 'https://api.example.com/graphql'.","message":"baseURL must not include a trailing slash. The package appends '/' internally.","severity":"gotcha","affected_versions":"all"},{"fix":"Add guard: if (!request.headers) request.headers = {};","message":"willSendRequest must set request.headers property if it does not exist, otherwise it may throw.","severity":"gotcha","affected_versions":"<1.2.0"}],"env_vars":null,"search_vec":"'1.3.2':20 '2.0':65 'activ':79 'allow':42 'api':16,52 'apollo':1,8,32,44,63,87 'cach':54 'connect':11 'coverag':85 'creat':7 'current':17 'data':47,72 'datasourc':3,9,88 'dedupl':55 'design':61 'differenti':41 'enabl':53 'error':57 'exist':14 'extern':28 'fetch':71 'graphql':2,15,29,39,51,68,89 'handl':58 'integr':27 'javascript':86 'key':40 'layer':49 'librari':5 'limit':83 'maintain':80 'note':73 'project':76 'provid':22 'queries/mutations':69 'restdatasourc':36 'server':33,45,64 'servic':30 'similar':34 'simpl':24 'sourc':48 'test':84 'use':43,67 'version':18 'way':25","created_at":"2026-06-07T16:49:01.087725+00:00","updated_at":"2026-06-07T16:49:01.087725+00:00","problems":[{"fix":"Run 'npm install apollo-datasource-graphql' and verify import path","cause":"Package not installed or typo in import path","error":"Cannot find module 'apollo-datasource-graphql'"},{"fix":"Ensure willSendRequest checks for context: if (this.context && this.context.token) { request.headers.authorization = this.context.token; }","cause":"Accessing this.context without checking if it exists or before willSendRequest runs","error":"TypeError: Cannot read property 'authorization' of undefined"},{"fix":"Ensure the first argument is a parsed GraphQL document: const query = gql`...`; then this.query(query)","cause":"Calling this.query() without a valid GraphQL document (gql result)","error":"GraphQLError: Must provide Source. Received: undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/poetic/apollo-datasource-graphql#readme","github":"https://github.com/poetic/apollo-datasource-graphql","docs":null,"changelog":null,"pypi":null,"npm":"apollo-datasource-graphql","openapi_spec":null,"status_page":null,"smithery":null,"categories":["api"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}