-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0458ccb
commit 3759877
Showing
8 changed files
with
82 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import './morpher/client'; | ||
import './accounts/client'; | ||
import './default/client'; | ||
import './ejson/client'; |
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,30 @@ | ||
import client, { wsLink } from '../apolloClient'; | ||
import gql from 'graphql-tag'; | ||
import { loginWithPassword, logout } from 'meteor-apollo-accounts'; | ||
import { resolve } from 'dns'; | ||
import { EJSON } from 'meteor/ejson'; | ||
|
||
const PASSWORD = '12345'; | ||
|
||
describe('EJSON', () => { | ||
it('Should work properly', async () => { | ||
const response = await client.query({ | ||
query: gql` | ||
query($input: EJSON) { | ||
jsonTest(input: $input) | ||
} | ||
`, | ||
variables: { | ||
input: EJSON.stringify({ | ||
name: 'john', | ||
date: new Date(), | ||
}), | ||
}, | ||
}); | ||
|
||
const data = EJSON.parse(response.data.jsonTest); | ||
|
||
assert.isString(data.name); | ||
assert.isTrue(data.date instanceof Date); | ||
}); | ||
}); |
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,22 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
import { Accounts } from 'meteor/accounts-base'; | ||
import { load } from 'meteor/cultofcoders:apollo'; | ||
|
||
load({ | ||
typeDefs: ` | ||
type Query { | ||
jsonTest(input: EJSON): EJSON | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
jsonTest(_, { input }, { userId }) { | ||
console.log(`input`, input); | ||
|
||
return { | ||
...input, | ||
}; | ||
}, | ||
}, | ||
}, | ||
}); |
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,21 @@ | ||
import { GraphQLScalarType } from 'graphql'; | ||
import { Kind } from 'graphql/language'; | ||
import { EJSON } from 'meteor/ejson'; | ||
|
||
export default new GraphQLScalarType({ | ||
name: 'EJSON', | ||
description: 'EJSON custom scalar type', | ||
parseValue(value) { | ||
return EJSON.parse(value); | ||
}, | ||
serialize(value) { | ||
return EJSON.stringify(value); | ||
}, | ||
parseLiteral(ast) { | ||
if (ast.kind == Kind.STRING) { | ||
return EJSON.stringify(value); | ||
} | ||
|
||
return null; | ||
}, | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default ` | ||
scalar Date | ||
scalar JSON | ||
scalar EJSON | ||
`; |