-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #536 from vbotnaru/master
Moved query of log file content to GraphQL
- Loading branch information
Showing
18 changed files
with
550 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ArgsType, Field, Int } from 'type-graphql'; | ||
|
||
@ArgsType() | ||
export default class LogFileArgs { | ||
@Field(() => Int) | ||
numberOfLines: number; | ||
|
||
constructor() { | ||
this.numberOfLines = 500; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Args, Query, Resolver } from 'type-graphql'; | ||
import { Service } from 'typedi'; | ||
import LogFileService from '../../services/LogFile'; | ||
import LogFile from '../../models/LogFile'; | ||
import LogFileArgs from '../args/LogFile'; | ||
|
||
@Service() | ||
@Resolver() | ||
export default class LogFileResolver { | ||
constructor(private logFileService: LogFileService) {} | ||
|
||
@Query(() => LogFile) | ||
async logFile(@Args() args: LogFileArgs): Promise<LogFile> { | ||
const content = await this.logFileService.loadLogFile(args); | ||
return { content }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { GraphQLScalarType, Kind } from 'graphql'; | ||
|
||
const JSONObjectScalar = new GraphQLScalarType({ | ||
name: 'JSONObject', | ||
description: 'JSON object', | ||
parseValue: (value) => { | ||
if (typeof value === 'object') { | ||
return value; | ||
} | ||
if (typeof value === 'string') { | ||
return JSON.parse(value); | ||
} | ||
return null; | ||
}, | ||
serialize: (value) => { | ||
if (typeof value === 'object') { | ||
return value; | ||
} | ||
if (typeof value === 'string') { | ||
return JSON.parse(value); | ||
} | ||
return null; | ||
}, | ||
parseLiteral: (ast) => { | ||
switch (ast.kind) { | ||
case Kind.STRING: | ||
return JSON.parse(ast.value); | ||
case Kind.OBJECT: | ||
throw new Error(`Not sure what to do with OBJECT for ObjectScalarType`); | ||
default: | ||
return null; | ||
} | ||
}, | ||
}); | ||
|
||
export default JSONObjectScalar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Field, ObjectType } from 'type-graphql'; | ||
import JSONObjectScalar from '../graphql/scalars/JSONObjectScalar'; | ||
|
||
@ObjectType('LogEntry') | ||
export default class LogEntry { | ||
@Field() | ||
level: string; | ||
|
||
@Field() | ||
message: string; | ||
|
||
@Field() | ||
timestamp: string; | ||
|
||
@Field(() => JSONObjectScalar, { nullable: true }) | ||
context?: unknown; | ||
|
||
constructor( | ||
level: string, | ||
message: string, | ||
timestamp: string, | ||
context?: unknown | ||
) { | ||
this.level = level; | ||
this.message = message; | ||
this.timestamp = timestamp; | ||
this.context = context; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Field, ObjectType } from 'type-graphql'; | ||
import LogEntry from './LogEntry'; | ||
|
||
@ObjectType('LogFile') | ||
export default class LogFile { | ||
@Field(() => [LogEntry], { nullable: true }) | ||
content: LogEntry[]; | ||
|
||
constructor(content: LogEntry[]) { | ||
this.content = content; | ||
} | ||
} |
Oops, something went wrong.