
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
apollo-server-tools
Advanced tools
Helper for apollo-server
Install with npm:
$ npm install --save apollo-server-tools
import path from 'path';
import fs from 'smart-fs';
import { syncDocs, CommentVersionPlugin } from 'apollo-server-tools';
import { ApolloServer } from 'apollo-server';
import axios from 'axios';
import { makeExecutableSchema } from '@graphql-tools/schema';
const typeDefs = `
type Query {
"[deprecated] 1.0.0 Deprecated, add reason and what to do..."
messages: [Message!]!
}
"[deprecated] 2.0.0 Also Deprecated, notice the date"
type Message {
id: String
"[deprecated] 3.0.0 Yep, Deprecated, we can deprecate everything now"
content: String
"[required] 3.0.0"
payload: String
}
`;
const resolvers = {
Query: {
messages: () => [
{ id: 1, content: 'Data', payload: null }
]
}
};
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [CommentVersionPlugin({
apiVersionHeader: 'x-api-version',
forceSunset: false,
sunsetDurationInDays: 7 * 52,
versions: {
'0.0.1': '2018-01-01',
'1.0.0': '2019-01-01',
'2.0.0': '2019-02-02',
'3.0.0': '2019-03-03'
}
})],
parseOptions: {
// allows line comments as per https://github.com/ardatan/graphql-tools/issues/3645#issuecomment-934653324
commentDescriptions: true
},
introspection: false // clients should obtain this from the generated file (see below)
});
// --- deprecation header are returned when deprecated functionality is accessed
server.listen().then(async (serverInfo) => {
const r = await axios({
method: 'POST',
url: `${serverInfo.url}graphql`,
data: { query: 'query Messages { messages { id, content } }' },
headers: {
'x-api-version': '0.0.1'
}
});
// As per example https://tools.ietf.org/html/draft-dalal-deprecation-header-00#section-5
console.log('Deprecation Header:', r.headers.deprecation);
console.log('Sunset Header:', r.headers.sunset);
console.log('Response Body:', JSON.stringify(r.data));
serverInfo.server.close();
});
// --- how you could sync graph api documentation to file
syncDocs(
path.join(fs.dirname(import.meta.url), 'graph-docs.json'),
makeExecutableSchema({ typeDefs, parseOptions: {} })
);
Parse info object to easily access relevant information.
Parse out relevant deprecation information for all accessed functionality.
Expects custom deprecation syntax, see below.
The versions
parameter is expected to be an object mapping versions to their respective introduction Date.
Can e.g. be used to return a Sunset
header.
Fetch deprecated entities that are accessed by the query. Expects custom deprecation syntax, see below.
Graphql Plugin that injects appropriate headers into responses.
If forceSunset is set to true and sunset functionality is accessed, an error is thrown.
Versions is expected to be an object mapping versions to their creation date string as "YYYY-MM-DD".
Can make optional arguments required from a certain version by using e.g [required] 1.0.0
as a comment.
Used to do extra validation on all arguments. Can be used to reject certain input by returning false from callback
See test and code for additional details.
Write introspection result into file. Order is stable. Returns true iff the content has changed. Deprecated entities are removed if option is set. Expects custom deprecation syntax, see below.
Generate and return introspection result. Deprecated entities are removed if option is set. Expects custom deprecation syntax, see below.
Deprecation functionality is very limited in graphql. This tool allows overloading of comments, which means that everything in the schema can be deprecated.
The deprecation comment is expected to be in the form [deprecated] YYYY-MM-DD description
, where the date indicates the date of deprecation.
FAQs
Helper for apollo-server
The npm package apollo-server-tools receives a total of 128 weekly downloads. As such, apollo-server-tools popularity was classified as not popular.
We found that apollo-server-tools demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.