-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mappingConverter): Replace invalid GraphQL characters on underscore.
Related #9
- Loading branch information
Showing
2 changed files
with
81 additions
and
15 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,6 +1,6 @@ | ||
/* @flow */ | ||
|
||
import { TypeComposer, GraphQLJSON, graphql } from 'graphql-compose'; | ||
import { TypeComposer, GraphQLJSON, graphql, GQC } from 'graphql-compose'; | ||
import { | ||
convertToSourceTC, | ||
propertyToSourceGraphQLType, | ||
|
@@ -225,4 +225,65 @@ describe('PropertiesConverter', () => { | |
expect(getSubFields('range')).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('issue #9', () => { | ||
const mapping9 = { | ||
properties: { | ||
$id: { | ||
type: 'long', | ||
}, | ||
lastName: { | ||
type: 'string', | ||
}, | ||
email: { | ||
type: 'string', | ||
analyzer: 'email_analyzer', | ||
}, | ||
$passwordHash: { | ||
type: 'string', | ||
index: 'not_analyzed', | ||
}, | ||
}, | ||
}; | ||
const tc9 = convertToSourceTC(mapping9, 'Type9'); | ||
|
||
it('should replace unacceptable characters in GraphQL fieldnames', () => { | ||
expect(tc9).toBeInstanceOf(TypeComposer); | ||
expect(tc9.getFieldNames()).toEqual( | ||
expect.arrayContaining(['_id', 'lastName', 'email', '_passwordHash']) | ||
); | ||
}); | ||
|
||
it('should work with graphql schema without errors', () => { | ||
GQC.rootQuery().addFields({ userES: tc9 }); | ||
expect(() => GQC.buildSchema()).not.toThrowError(); | ||
}); | ||
|
||
it('should use Elastic field names from source', async () => { | ||
GQC.rootQuery().addFields({ userES: tc9 }); | ||
const result = await graphql.graphql( | ||
GQC.buildSchema(), | ||
`query { userES { _id, lastName, email, _passwordHash } }`, | ||
{ | ||
// simulate elastic responce | ||
userES: { | ||
$id: 123, | ||
lastName: 'Tyler', | ||
email: '[email protected]', | ||
$passwordHash: 'abc1234def', | ||
}, | ||
} | ||
); | ||
expect(result).toEqual({ | ||
data: { | ||
userES: { | ||
_id: 123, | ||
lastName: 'Tyler', | ||
email: '[email protected]', | ||
_passwordHash: 'abc1234def', | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
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