
Security News
Python Adopts Standard Lock File Format for Reproducible Installs
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
apollo-server-autoloader
Advanced tools
This package enables autoloading of schemas, resolvers and datasources based on configurable naming conventions.
npm i apollo-server-autoloader
# or
yarn add apollo-server-autoloader
The following example asumes, that you define your types, resolvers and datasources in the api
folder of your project.
import * as path from 'path'
import { buildFederatedSchema } from '@apollo/federation'
import { ApolloServer } from '...'
import { Autoloader } from 'apollo-server-autoloader'
const autoloaderConfig = {
searchPaths: [path.resolve(__dirname, 'api')]
}
const createServer = async () => {
import autoloader = Autoloader(autoloaderConfig)
const typeDefs = await autoloader.getTypeDefs()
const resolvers = await autoloader.getResolvers()
const datasources = await autoloader.getDatasources()
return new ApolloServer({
dataSources,
schema: buildFederatedSchema([{ typeDefs, resolvers }])
...
});
}
interface AutoloaderConfig {
// (required) search paths
searchPaths: string[]
// naming conventions
conventions?: FileNamingConventions
// which file extensions should be considered
fileExtensions?: string[]
// which files should be excluded (regex)
exclude: string[]
}
interface FileNamingConventions {
// naming conventions for schema files
types?: NamingConvention
// naming conventions for resolver files
resolvers?: NamingConvention
// naming conventions for datasource files
datasources?: NamingConvention
}
interface NamingConvention {
// The "key" is the pattern for the file name
// The ExportPattern is the pattern for the export variable
// If your schemas for example are located in files
// which are named "schema.ts" and they provide an export
// variable named "typeDef" the naming convention would look like follows:
// { schema: 'typeDef' }
[key: string]: ExportPattern
}
Asume your project structure looks like follows:
|- /api
|- |- schemaFile.ts
|- |- queriesFile.ts
|- |- mutationsFile.ty
|- |- DatasourceFile.ts
|- |- /subolder
|- |- |- schemaFile.ts
...
Your file exports look like follows:
// schemaFile.ts
export const myTypeDef = gql`...`
// queriesFile.ts
export const myQueries = { ... }
// mutationsFile.ts
export const myMutations = { ... }
// DatasourceFile.ts
export class MyDatasource { ... }
In this case the corresponding config for the autoloader should look like follows:
const config = {
searchPaths: [path.resolve(__dirname, 'api')],
conventions: {
types: {
schemaFile: 'myTypeDef',
},
resolvers: {
queriesFile: 'myQueries',
mutationsFile: 'myMutations',
},
datasources: {
DatasourceFile: 'MyDatasource',
}
},
fileExtensions: ['.ts'],
exclude: ['[^\/]+\.(spec|test)', '__tests__'],
}
The default config for the autoloader looks like follows:
export const defaultConfig: AutoloaderConfig = {
searchPaths: ['.'],
conventions: {
types: { schema: 'typeDef' },
resolvers: { queries: 'queries', mutations: 'mutations' },
datasources: { Datasource: 'Datasource' },
},
fileExtensions: ['ts']
}
If you don't change the config, this means you must name your schema files schema.ts
, your resolver files queries.ts
or mutations.ts
and your datasource files Datasource.ts
. The export for schema files must be named typeDef
, for resolver files queries
or mutations
and Datasource
for datasource files.
FAQs
auto loading schemas, resolvers and datasources
The npm package apollo-server-autoloader receives a total of 33 weekly downloads. As such, apollo-server-autoloader popularity was classified as not popular.
We found that apollo-server-autoloader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
Security News
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.