React native not sending real file data to server (Meteor + Apollo).
See original GitHub issuethe client side mutation
const UPLOAD_IMAGE = gql`
mutation uploadImage($file: Upload!) {
uploadImage(file: $file)
}
`;
const file = new ReactNativeFile({
uri, // From camera roll
name: 'testing',
type: 'image/jpeg',
});
uploadAvatar({
variables: {
file,
},
});
the client side setup
...
const httpLink = createUploadLink({ uri: api });
const link = split(
// split based on operation type
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
},
wsLink,
httpLink,
);
const client = new ApolloClient({
link: ApolloLink.from([middleWareLink, errorLink, stateLink, authLink, link]),
cache,
});
the server side setup (meteor)
import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas';
// Resolvers
import { accountTypeDefs, accountResolvers } from './account';
import { categoriesResolvers } from './categories';
...
// TypeDefs
import types from './schema.graphql';
// I have declared "scalar Upload" in schema.graphql already
const resolvers = mergeResolvers([
...accountResolvers,
...categoriesResolvers,
...
{
Upload: GraphQLUpload
},
]);
const typeDefs = mergeTypes([...accountTypeDefs, types]);
const schema = makeExecutableSchema({ typeDefs, resolvers });
createApolloServer(
{
schema,
},
{
graphiql: true,
configServer: (expressServer) => {
expressServer.use(bodyParser.json({ limit: '5mb' }));
expressServer.use(graphqlUploadExpress());
},
},
);
The server receives an object instead of a Promise for further processing.
{
uri, // From camera roll
name: 'testing',
type: 'image/jpeg',
}
I’ve read a lot of the related issues but not sure which parts are incorrect. thanks!!
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Integrating with Meteor - Apollo GraphQL Docs
Connect your express server to Meteor's existing server with WebApp.connectHandlers.use; Do not end the connection with res.send() and res.end() use req.
Read more >Upload image from React Native to Apollo Server not ...
I have created my backend with Nodejs and Apollo Server . I am trying to upload an image from my React Native client....
Read more >1: GraphQL Set up
This package uses Meteor DDP as data layer and Apollo as GraphQL implementation. 1.2 Set up server. Create a new file called graphql.js...
Read more >Building Chatty — Part 4: GraphQL Mutations
A WhatsApp clone with React Native and Apollo ... While GraphQL Queries let us fetch data from our server, GraphQL Mutations allow us...
Read more >Meteor and React Native - Create a native mobile app
Meteor and React Native are not integrated with each other by default However, there are great packages out there, that help us to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @mike-marcacci @jaydenseric, you are right. It was the client side problem. There was a middleware link parsed the ReactNativeFile type to String. It was resolved after removing that link. Thank you very much!
There was an Apollo link at Apollo Client acted as a middleware to ignore the typename for any mutation. It prevent the __typename is injected in the variable of any mutation but also stringify the of ReactNativeFile type so I removed it.