Skip to content

how to get all defined scalars #3692

Answered by ardatan
Diluka asked this question in Q&A
Oct 13, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

You can load and merge the type definitions;
https://www.graphql-tools.com/docs/schema-merging#file-loading

Then iterate over the definitions in DocumentNode and filter out scalar type definitions like definition.kind === 'ScalarTypeDefinition'.

Something like below to summarize;

import { loadFilesSync } from '@graphql-tools/load';
import { mergeTypeDefs } from '@graphql-tools/merge';
import { join } from 'path';
import { Kind } from 'graphql';

const scalarTypeNames = new Set<string>();
const typeDefs = mergeTypeDefs(loadFilesSync(join(__dirname, './types')));
for (const definition of typeDefs.definitions) {
  if (definition.kind === Kind.SCALAR_TYPE_DEFINITION) {
     scalarTypeNames.add(

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Diluka
Comment options

@ardatan
Comment options

Answer selected by Diluka
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants