Skip to content

Commit

Permalink
Merge pull request #36 from PRATHAM1ST/feat/21-implement-graphql
Browse files Browse the repository at this point in the history
fixed things and improved types
  • Loading branch information
PRATHAM1ST authored Sep 28, 2023
2 parents 4c083a8 + 39d73d6 commit 34ad114
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 30 deletions.
74 changes: 51 additions & 23 deletions controllers/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,58 @@
import { buildSchema } from "graphql";
import {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLList,
GraphQLBoolean,
} from "graphql";
import membersListLatest from "../data/members-list.json";
import { Member } from "./member";

const schema = buildSchema(`
type Member {
login: String!
name: String
tfa_enabled: Boolean!
is_public: Boolean!
role: String
last_active: String
saml_name_id: String
username: String
profile_pic_url: String
followers: String
following: String
repositories: String
bio: String
github_link: String
}
/* eslint-disable camelcase */

type Query {
members: [Member!]!
member(username: String!): Member
}
`);
const MemberType = new GraphQLObjectType<Member>({
name: "Member",
fields: () => ({
login: { type: GraphQLString },
name: { type: GraphQLString },
tfa_enabled: { type: GraphQLBoolean },
is_public: { type: GraphQLBoolean },
role: { type: GraphQLString },
last_active: { type: GraphQLString },
saml_name_id: { type: GraphQLString },
username: { type: GraphQLString },
profile_pic_url: { type: GraphQLString },
followers: { type: GraphQLString },
following: { type: GraphQLString },
repositories: { type: GraphQLString },
bio: { type: GraphQLString },
github_link: { type: GraphQLString },
}),
});

const QueryType = new GraphQLObjectType({
name: "Query",
fields: {
members: {
type: new GraphQLList(MemberType),
resolve: () => membersListLatest,
},
member: {
type: MemberType,
args: {
username: { type: GraphQLString },
},
resolve: (root, { username }) =>
membersListLatest.find(
(member) => member.username === username
),
},
},
});

const schema = new GraphQLSchema({
query: QueryType,
});

const root = {
members: (): Member[] => {
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"cors": "^2.8.5",
"express": "^4.18.2",
"express-graphql": "^0.12.0",
"graphql": "^16.8.1",
"graphql": "^15.8.0",
"linkedom": "^0.15.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion routes/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { graphqlHTTP } from "express-graphql";

const router = express.Router();

router.use(
router.all(
"/",
graphqlHTTP({
schema: controllers.schema,
Expand Down

0 comments on commit 34ad114

Please sign in to comment.