Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'graphql-import' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
private processBindings(
schemaPath: string | undefined
): { 'prepare-binding': { output: string; generator: string } } {
const generator: string = this.determineGenerator()
// TODO: This does not support custom generators
const extension = generator.endsWith('ts') ? 'ts' : 'js'
const outputPath: string = this.determineBindingOutputPath(extension)
const schema: string = this.determineInputSchema(schemaPath)
const schemaContents: string = importSchema(schema)
const finalSchema: string = generateCode(schemaContents, generator)
fs.writeFileSync(outputPath, finalSchema, { flag: 'w' })
return { 'prepare-binding': { output: outputPath, generator: generator } }
}
function buildTypeDefsString(typeDefs) {
let typeDefinitions = mergeTypeDefs(typeDefs);
// read from .graphql file if path provided
if (typeDefinitions.endsWith('graphql')) {
const schemaPath = path.resolve(typeDefinitions);
if (!fs.existsSync(schemaPath)) {
throw new Error(`No schema found for path: ${schemaPath}`);
}
typeDefinitions = importSchema(schemaPath);
}
return typeDefinitions;
}
resolverValidationOptions,
typeDefs,
resolvers,
} = props
// read from .graphql file if path provided
if (typeDefs.endsWith('graphql')) {
const schemaPath = path.isAbsolute(typeDefs)
? path.resolve(typeDefs)
: path.resolve(typeDefs)
if (!fs.existsSync(schemaPath)) {
throw new Error(`No schema found for path: ${schemaPath}`)
}
typeDefs = importSchema(schemaPath)
}
this.executableSchema = makeExecutableSchema({
directiveResolvers,
schemaDirectives,
resolverValidationOptions,
typeDefs,
resolvers,
})
}
if (props.middlewares) {
const { schema, fragmentReplacements } = applyFieldMiddleware(
this.executableSchema,
...props.middlewares,
)
import { importSchema } from 'graphql-import'
import { GraphQLServer } from 'graphql-yoga'
import { Prisma } from './generated/prisma'
import { resolvers } from './resolvers'
// Config --------------------------------------------------------------------
const APP_SCHEMA_PATH = './src/schema.graphql'
const typeDefs = importSchema(APP_SCHEMA_PATH)
// Server --------------------------------------------------------------------
const server = new GraphQLServer({
typeDefs,
resolvers,
context: req => ({
...req,
db: new Prisma({
endpoint: process.env.PRISMA_ENDPOINT,
secret: process.env.PRISMA_SECRET
})
})
})
server.start({ port: 5000 },() => {
import { GraphQLServer } from "graphql-yoga"
import { importSchema } from "graphql-import"
import { S3 } from 'aws-sdk'
import { Prisma } from "./generated/prisma"
import { resolvers } from "./resolvers"
import { files } from './files'
// Config --------------------------------------------------------------------
const APP_SCHEMA_PATH = './src/schema.graphql'
const typeDefs = importSchema(APP_SCHEMA_PATH)
const s3client = new S3({
accessKeyId: process.env.S3_KEY,
secretAccessKey: process.env.S3_SECRET,
params: {
Bucket: process.env.S3_BUCKET
}
})
// Server --------------------------------------------------------------------
const server = new GraphQLServer({
typeDefs,
resolvers,
context: req => ({
import express from 'express';
import compression from 'compression';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import { ApolloServer, gql } from 'apollo-server-express';
import { importSchema } from 'graphql-import';
import { getResolver } from './graphql/resolvers';
import { db } from './db';
// A map of functions which return data for the schema.
const resolvers = getResolver();
const type = importSchema('./src/graphql/types/schema.graphql');
// The GraphQL schema
const typeDefs = gql`
${type}
`;
const apollo = new ApolloServer({
typeDefs,
resolvers,
rootValue: db,
tracing: true,
});
export const app = express();
apollo.applyMiddleware({ app });
import { importSchema } from 'graphql-import';
import { makeExecutableSchema } from 'graphql-tools';
import resolvers from './resolvers';
const typeDefs = importSchema(`${__dirname}/typeDefs.graphql`);
export default makeExecutableSchema({ typeDefs, resolvers });
)
}
}
}
const db = new Prisma({
fragmentReplacements: extractFragmentReplacements(resolvers),
typeDefs: "src/generated/prisma.graphql",
endpoint: process.env.PRISMA_ENDPOINT,
secret: process.env.PRISMA_SECRET,
debug: true
})
console.log(process.env.PRISMA_ENDPOINT)
const schema = makeExecutableSchema({
typeDefs: importSchema("./src/schema.graphql"),
resolvers,
directiveResolvers
})
const server = new GraphQLServer({
schema,
context: req => ({
...req,
db
})
})
server.express.post(
server.options.endpoint,
checkJwt,
(err, req, res, next) => {
import { makeExecutableSchema } from 'graphql-tools';
import { importSchema } from 'graphql-import';
import resolvers from './resolvers';
const typeDefs: string = importSchema('src/graphql/schema/schema.graphql');
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
export default schema;
const setup = app => {
const path = '/graphql';
const server = new ApolloServer({
typeDefs: importSchema('src/graphql/schema.graphql'),
resolvers,
playground: { settings: { 'request.credentials': 'include' } },
context: ({ req }) => {
return { user: req.user };
}
});
app.use(path, authMiddleware);
server.applyMiddleware({ app, path });
};