Skip to content

Commit

Permalink
Replace local questions with repo questions
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardconstantin committed Jul 16, 2023
1 parent a104c5d commit cedb966
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions pages/api/graphql.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// import { CosmosContainer } from "@azure-fundamentals/src/graphql/cosmos-client";
// import { QuestionsDataSource, LocalQuestionsDataSource } from "@azure-fundamentals/src/graphql/questionsDataSource";
import { ApolloServer, BaseContext } from "@apollo/server";
import { startServerAndCreateNextHandler } from "@as-integrations/next";
import typeDefs from "@azure-fundamentals/src/graphql/schemas";
import resolvers from "@azure-fundamentals/src/graphql/resolvers";
import { CosmosContainer } from "@azure-fundamentals/src/graphql/cosmos-client";
import { QuestionsDataSource, LocalQuestionsDataSource } from "@azure-fundamentals/src/graphql/questionsDataSource";
import qdb from "@azure-fundamentals/src/qdb.json";
import { RepoQuestionsDataSource } from "@azure-fundamentals/src/graphql/questionsDataSource";
import { FetchQuestions } from "@azure-fundamentals/src/graphql/repoQuestions";

interface ContextValue {
dataSources: {
Expand All @@ -18,13 +19,16 @@ const server = new ApolloServer<ContextValue>({
introspection: process.env.NODE_ENV !== "production",
});

const questions = await FetchQuestions();

export default startServerAndCreateNextHandler(server, {
context: async () => {
return {
dataSources: {
questionsDB: process.env.AZURE_COSMOSDB_ENDPOINT
? QuestionsDataSource(CosmosContainer())
: LocalQuestionsDataSource(qdb),
// questionsDB: process.env.AZURE_COSMOSDB_ENDPOINT
// ? QuestionsDataSource(CosmosContainer())
// : LocalQuestionsDataSource(questions),
questionsDB: RepoQuestionsDataSource(questions),
},
};
},
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/questionsDataSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const QuestionsDataSource = (container: Container) => {
};
};

export const LocalQuestionsDataSource = (container: any) => {
export const RepoQuestionsDataSource = (container: any) => {
return {
async getQuestion(id: string) {
try {
Expand Down

0 comments on commit cedb966

Please sign in to comment.